My connection string:
con = new SqlConnection("Server=localhost;Database=mainDB;User Id=sqluser;Password=Y;9r.5JQ6cwy@)V_");
That semicolon in the password causes an exception. How do I write this password into a connection string?
Using a non-standard portServer=myServerName,myPortNumber;Database=myDataBase;User Id=myUsername;Password=myPassword; The default SQL Server port is 1433 and there is no need to specify that in the connection string.
You can either use the new operator to make that directly. For example: SqlConnection conn = new SqlConnection( new SqlConnectionStringBuilder () { DataSource = "ServerName", InitialCatalog = "DatabaseName", UserID = "UserName", Password = "UserPassword" }. ConnectionString );
Simply use like this.
con = new SqlConnection("Server=localhost;Database=mainDB;User Id=sqluser;Password='Y;9r.5JQ6cwy@)V_'");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With