SQLDBA SQLDBA - 4 months ago 27
SQL Question

SQL Server 2008 password ending in a semicolon

Let's say I have a password that looks like this: password;

How can I get it to work with a semicolon as the last character. The password works in SSMS and ODBC, but not with the connection string. I've tried

"
around it but that does not seem to work.

<add name="DbConn" connectionString="Data Source=LOCALHOST;Database=MYDB;Trusted_Connection=no;User Id=myuser;Password=password;" providerName="System.Data.SqlClient" />


This is for an ASP.NET web application. As far as I can tell, it is impossible.

Answer

I am using the following code to connect to SQL Server 2008 R2.

  var sqlConnection = new SqlConnection()
            {
                ConnectionString = "Server=DT2719MOD;Database=abs2;User Id=TestUserLogon;Password='iloveachallenge;';"

            };
        sqlConnection.Open();
        Console.WriteLine(sqlConnection.State);
        sqlConnection.Close();

Edit: Also tried to use the connection string that you have and it works on my machine.

ConnectionString="Data Source=DT2719MOD;Database=abs2;Trusted_Connection=no;User Id=TestUserLogon;Password='iloveachallenge;';"