Skip to content

Commit

Permalink
Refactored MsSqlConnectionStringBuilder to remove dependencies. (#395)
Browse files Browse the repository at this point in the history
* Changed  MsSqlConnectionStringBuilder to remove the need of System.Data.SqlClient.SqlConnectionStringBuilder and System.Data.SqlClient

* Added space support for MsSqlConnectionStringBuilder connectionString
  • Loading branch information
danilobreda authored and jrgcubano committed Apr 17, 2018
1 parent c68f8aa commit 0a7c1b5
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/FluentNHibernate/Cfg/Db/MsSqlConnectionStringBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Data.SqlClient;
using System.Text;

namespace FluentNHibernate.Cfg.Db
{
Expand Down Expand Up @@ -52,20 +52,34 @@ protected internal override string Create()
if (!string.IsNullOrEmpty(connectionString))
return connectionString;

var builder = new SqlConnectionStringBuilder(connectionString)
{
DataSource = server,
InitialCatalog = database,
IntegratedSecurity = trustedConnection
};
var sb = new StringBuilder();

if (server.Contains(" "))
sb.AppendFormat("Data Source=\"{0}\"", server);
else
sb.AppendFormat("Data Source={0}", server);

if (database.Contains(" "))
sb.AppendFormat(";Initial Catalog=\"{0}\"", database);
else
sb.AppendFormat(";Initial Catalog={0}", database);

sb.AppendFormat(";Integrated Security={0}", trustedConnection);

if (!trustedConnection)
{
builder.UserID = username;
builder.Password = password;
if (username.Contains(" "))
sb.AppendFormat(";User Id=\"{0}\"", username);
else
sb.AppendFormat(";User Id={0}", username);

if (password.Contains(" "))
sb.AppendFormat(";Password=\"{0}\"", password);
else
sb.AppendFormat(";Password={0}", password);
}

return builder.ToString();
return sb.ToString();
}
}
}

0 comments on commit 0a7c1b5

Please sign in to comment.