我的連接字符串:如何在SQL連接字符串的密碼中使用分號字符?
con = new SqlConnection("Server=localhost;Database=mainDB;User Id=sqluser;Password=Y;[email protected])V_");
,在密碼分號導致異常。如何將此密碼寫入連接字符串?
我的連接字符串:如何在SQL連接字符串的密碼中使用分號字符?
con = new SqlConnection("Server=localhost;Database=mainDB;User Id=sqluser;Password=Y;[email protected])V_");
,在密碼分號導致異常。如何將此密碼寫入連接字符串?
您是否考慮過使用SqlConnectionStringBuilder
?
var sqlBuilder = new SqlConnectionStringBuilder
{
DataSource = "localhost",
InitialCatalog = "mainDB",
Password = "Y;[email protected])V_",
UserID = "sqluser"
};
con = new SqlConnection(sqlBuilder.ToString());
你打我吧:)'sqlBuilder.ConnectionString'可以用來代替'sqlBuilder.ToString()'。 –
嘗試使用
Password='Y;[email protected])V_'
或
Password={Y;[email protected])V_}
見https://msdn.microsoft.com/en-us/library/windows/desktop/ms722656(v=vs.85).aspx
也許你可以設置SqlCredentials算賬:
con = new SqlConnection("Server=localhost;Database=mainDB;User Id=sqluser;Password=dummy");
con.Credential = new SqlCredential("sqluser", "Y;[email protected])V_");
只需像這樣使用。
con = new SqlConnection("Server=localhost;Database=mainDB;User Id=sqluser;Password='Y;[email protected])V_'");
欲瞭解更多信息 https://stackoverflow.com/questions/23014180/sql-server-2008-password-ending-in-a-semicolon –
爲什麼不直接在密碼中使用不同的字符?將它改爲克拉或其他東西。^ –
用引號括起密碼值。 –
@SeanLange我不是數據庫管理員,我沒有權限。 – Nathan