tags:

views:

34

answers:

4
using (SqlConnection conn = new SqlConnection("Data Source=SARAN-PC\SQLEXPRESS;Initial Catalog=ERP;integrated security=SSPI"))
{}

when i include this line in asp.net web application,it shows..(Unrecognised escape sequence as error) locating \S in the connection string... help me to connect.. Thanks a lot

+2  A: 

It's the "\" in your string that C# is interpreting as an escape sequence (for example a carriage return).

You can either:

using (SqlConnection conn = new SqlConnection(@"Data Source=SARAN-PC\SQLEXPRESS;Initial Catalog=ERP;integrated security=SSPI")) {}

Note the @ symbol.

or, you could use a double backslash:

using (SqlConnection conn = new SqlConnection("Data Source=SARAN-PC\\SQLEXPRESS;Initial Catalog=ERP;integrated security=SSPI")) {}
DavidGouge
+2  A: 
using (SqlConnection conn = new SqlConnection("Data Source=SARAN-PC\\SQLEXPRESS;Initial Catalog=ERP;integrated security=SSPI")) {}

Or

using (SqlConnection conn = new SqlConnection(@"Data Source=SARAN-PC\SQLEXPRESS;Initial Catalog=ERP;integrated security=SSPI")) {}
Alex Reitbort
+2  A: 

Add the @ sign before the start of your string to ignore escape sequences.

new SqlConnection(@"Data Source=SARAN-PC\SQLEXPRESS;Initial Catalog=ERP;integrated security=SSPI")) 
VdesmedT
A: 

All answers are correct but you shouldn't hardcode this string. Read it from resource or configuration file.

Hugo Riley