Skip to content

Commit 0a7c1b5

Browse files
danilobredajrgcubano
authored andcommitted
Refactored MsSqlConnectionStringBuilder to remove dependencies. (#395)
* Changed MsSqlConnectionStringBuilder to remove the need of System.Data.SqlClient.SqlConnectionStringBuilder and System.Data.SqlClient * Added space support for MsSqlConnectionStringBuilder connectionString
1 parent c68f8aa commit 0a7c1b5

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/FluentNHibernate/Cfg/Db/MsSqlConnectionStringBuilder.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Data.SqlClient;
1+
using System.Text;
22

33
namespace FluentNHibernate.Cfg.Db
44
{
@@ -52,20 +52,34 @@ protected internal override string Create()
5252
if (!string.IsNullOrEmpty(connectionString))
5353
return connectionString;
5454

55-
var builder = new SqlConnectionStringBuilder(connectionString)
56-
{
57-
DataSource = server,
58-
InitialCatalog = database,
59-
IntegratedSecurity = trustedConnection
60-
};
55+
var sb = new StringBuilder();
56+
57+
if (server.Contains(" "))
58+
sb.AppendFormat("Data Source=\"{0}\"", server);
59+
else
60+
sb.AppendFormat("Data Source={0}", server);
61+
62+
if (database.Contains(" "))
63+
sb.AppendFormat(";Initial Catalog=\"{0}\"", database);
64+
else
65+
sb.AppendFormat(";Initial Catalog={0}", database);
66+
67+
sb.AppendFormat(";Integrated Security={0}", trustedConnection);
6168

6269
if (!trustedConnection)
6370
{
64-
builder.UserID = username;
65-
builder.Password = password;
71+
if (username.Contains(" "))
72+
sb.AppendFormat(";User Id=\"{0}\"", username);
73+
else
74+
sb.AppendFormat(";User Id={0}", username);
75+
76+
if (password.Contains(" "))
77+
sb.AppendFormat(";Password=\"{0}\"", password);
78+
else
79+
sb.AppendFormat(";Password={0}", password);
6680
}
6781

68-
return builder.ToString();
82+
return sb.ToString();
6983
}
7084
}
7185
}

0 commit comments

Comments
 (0)