Connection string error in visual studio 2015

2

When I put the connection string, the following error appears:

Con = new SqlConnection("Data Source=(localdb)\MSSQLLocalDB;OutrosParametros");
  

Represents text as a series of Unicode characters

When I put two slashes ( \ ) the error some.

Can I use \\?

    
asked by anonymous 19.12.2016 / 16:11

2 answers

3

The message

  

Represents text as a series of Unicode characters

is not an error, it is the description of string .

The code actually has an error that is to use \ as literal, this character needs to be escaped.

There are two options for this:

  • Use \ to escape this character only.

    Ex: "Teste\Teste "equals Teste\Teste .

    new SqlConnection("Data Source=(localdb)\MSSQLLocalDB;OutrosParametros");
    
  • Use @ at the beginning of string . This will do what the text is represented that way. In other words, string turns a string literal (or verbatim string ).

    Ex: @"Teste\nTeste" is equal to Teste\nTeste .

    new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;OutrosParametros");
    
  • 19.12.2016 / 16:33
    1

    Place @ before your quotation mark ("")

        
    19.12.2016 / 16:14