Unrecognized escape sequence in SqlConnection constructor

Pranav Mishra picture Pranav Mishra · Sep 25, 2012 · Viewed 43.3k times · Source

when ever I make connection it gives an error

Unrecognized escape sequence.

NEPOLEON\ADMN HERE ON THIS SLASH. NEPOLEON\ADMN IS MY SQL SERVER NAME.

SqlConnection con = new SqlConnection("Server=NEPOLEON\ADMN;Database=MASTER;Trusted_Connection=True");

Answer

Dumitrescu Bogdan picture Dumitrescu Bogdan · Sep 25, 2012

Escape the \ character like :

SqlConnection con = new SqlConnection("Server=NEPOLEON\\ADMN;Database=MASTER;Trusted_Connection=True");

or

SqlConnection con = new SqlConnection(@"Server=NEPOLEON\ADMN;Database=MASTER;Trusted_Connection=True");