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;")
 
Joined
Jun 21, 2011
Messages
1
Reaction score
0
ERROR:unrecognized escape sequence

OleDbConnection conn;
OleDbCommand comm;
OleDbDataReader dr;
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\data1\jana.mdb");
comm = new OleDbCommand("insert into mans1 values('" + TextBox1.Text + "','" + TextBox2.Text + "')", conn);
conn.Open();
dr = comm.ExecuteReader();
conn.Close();


Here i got a error about the ms access connection string(unrecognized escape sequence).........

Also i tried { @"Data Source=C:\data1\jana.mdb" AND
"Data Source=C:\\data1\\jana.mdb" }......

what should i do......
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top