Unrecognized escape sequence

J

Jeff

Hey

asp.net 2.0

I'm developing a website using visual web developer 2005 express. In this
project I'm trying to connect to the aspnetdb.mdf database (the project's
own database created by wvd).

This is my connection string:
SqlConnection conn = new SqlConnection("Data Source=.\SQLEXPRESS;Integrated
Security=True;");

But the "\" in the connection string gives this error :
"unrecognized escape sequence"
But at this link they are using "\":
http://msdn2.microsoft.com/en-us/library/ms247257(d=printer).aspx

Any ideas what I should fix in my connection string so I can connect to the
database?

Jeff
 
C

Chris Chilvers

Hey

asp.net 2.0

I'm developing a website using visual web developer 2005 express. In this
project I'm trying to connect to the aspnetdb.mdf database (the project's
own database created by wvd).

This is my connection string:
SqlConnection conn = new SqlConnection("Data Source=.\SQLEXPRESS;Integrated
Security=True;");

But the "\" in the connection string gives this error :
"unrecognized escape sequence"
But at this link they are using "\":
http://msdn2.microsoft.com/en-us/library/ms247257(d=printer).aspx

Any ideas what I should fix in my connection string so I can connect to the
database?

Jeff

The \ character is used as the escape character in C#. This lets you use
things like \n for the newline character. Thus to put a \ in a C# string
you need to use \\ for one \.

new SqlConnection("Data Source=.\\SQLEXPRESS;Integrated Security=True;")

Alternativly you can place an @ at the start of the string (before the
quote character) to tell C# not to use escape characters for this
string.

new SqlConnection(@"Data Source=.\\SQLEXPRESS;Integrated
Security=True;")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top