Search code examples
c#sqlconnection

Unrecognized escape sequence in SqlConnection constructor


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

Solution

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