Unrecognized escape sequence in database connection string c#

Unrecognized escape sequence when we make connection string c#:

When we connect sql database in asp.net 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.

Unrecognized escape sequence:

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";

Asp.net related Other Post :


Comments

Popular posts from this blog