My connection string is:
Data Source=MAX-PC\SQLEXPRESS;Initial Catalog=newSchool;Integrated Security=True
but whenever I write :
SqlConnection conn = new SqlConnection("Data Source=MAX-PC\SQLEXPRESS;Initial Catalog=newSchool;Integrated Security=True");
it gives me an error
unrecognized escape sequence
under the \ in Max-PC\SQLEXPRESS
\ is a speacial character to create escape sequences. you can use \\ or you can put '@' beginning of your connection string to ignore escape characters
var conn = new SqlConnection(@"Data Source=MAX-PC\SQLEXPRESS;Initial Catalog=newSchool;Integrated Security=True");
C# will understand the '\S' as an escape character. The correct would be double back-slash, or the use of @ before the opening ".
SqlConnection conn = new SqlConnection("Data Source=MAX-PC\\SQLEXPRESS;Initial Catalog=newSchool;Integrated Security=True");
or
SqlConnection conn = new SqlConnection(@"Data Source=MAX-PC\SQLEXPRESS;Initial Catalog=newSchool;Integrated Security=True");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With