unrecognized escape sequence

I am getting an using visual studio 2010 on my SQL Connection String called "Unrecognized escape sequence".  It is saying the dash between TOM-PC and SQLExpress is an unrecognized escape sequence.  Any suggestions on how I can resolve this?
      
public string connectionString="Data Source=TOM-PC\SQLEXPRESS;Initial Catalog=PIESACES2;Persist Security Info=True;User ID=PIESACES;Password=Amajor99";    
HojoformoAsked:
Who is Participating?
 
mrjoltcolaConnect With a Mentor Commented:
Backslash is the escape char, so it thinks \S is an escape.

Change the string to a non-escaped one (add @)

public string connectionString= @"Data Source=TOM-PC\SQLEXPRESS;Initial Catalog=PIESACES2;Persist Security Info=True;User ID=PIESACES;Password=Amajor99";    

0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Or use \\
Inside a string that is translated into a single \ character when string is not declared with an @ at the start (before the opening " mark)
0
 
NavneetSoftware EngineerCommented:

Hi!

1. public string connectionString=@"Data Source=TOM-PC\SQLEXPRESS;Initial Catalog=PIESACES2;Persist Security Info=True;User ID=PIESACES;Password=Amajor99";
OR
2. public string connectionString=@"Data Source=TOM-PC\\SQLEXPRESS;Initial Catalog=PIESACES2;Persist Security Info=True;User ID=PIESACES;Password=Amajor99";

Thanks!
0
 
NavneetSoftware EngineerCommented:
Hi!

1. public string connectionString=@"Data Source=TOM-PC\SQLEXPRESS;Initial Catalog=PIESACES2;Persist Security Info=True;User ID=PIESACES;Password=Amajor99";
OR
2. public string connectionString="Data Source=TOM-PC\\SQLEXPRESS;Initial Catalog=PIESACES2;Persist Security Info=True;User ID=PIESACES;Password=Amajor99";

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.