Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have the semicolon character in a password for a SQL connection string?

Tags:

c#

sql

sql-server

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?

like image 490
Nathan Avatar asked Aug 17 '17 18:08

Nathan


People also ask

How do I pass UserName and password in SQL 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.

How do I connect to a SQL Server 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 );


1 Answers

Simply use like this.

con = new SqlConnection("Server=localhost;Database=mainDB;User Id=sqluser;Password='Y;9r.5JQ6cwy@)V_'");
like image 167
Power Star Avatar answered Nov 15 '22 14:11

Power Star