Search This Blog

Friday, October 20, 2017

Unrecognized escape sequence in database connection string c#

When we connect sql database in web site and make connection on page then many type we face this type of problem.

If you are new and you want to create connection at first time then it is possible that you face this problem.

As we know that we write fallowing code for make connection.

string connetionString = null;
            SqlConnection cnn ;
                     connetionString = "Data Source=PARIJAT-PC\PARIJAT;Initial Catalog=my_testing;Integrated Security=True";

            cnn = new SqlConnection(connetionString);

And get an Exaction or Unrecognized escape sequence error. Because you do not use  \ (forward sales) in string object.

For solving this here we give two option.

Use @ with connectionstring as like :

connetionString = @"Data Source=PARIJAT-PC\PARIJAT;Initial Catalog=my_testing;Integrated Security=True";

Use \\ sales in the place of single sales. Like as :

connetionString = "Data Source=PARIJAT-PC\\PARIJAT;Initial Catalog=my_testing;Integrated Security=True";

No comments:

Post a Comment