Solved

unrecognized escape sentence - Connection string

Posted on 2014-09-30
2
144 Views
Last Modified: 2014-10-07
I get an error  on the backslah that say unrecognized escape sentence   on  SVSQ02\macomb_test

con = new SqlConnection("Data Source=SVSQ02\macomb_test;Initial Catalog=DropDown;Integrated Security=True");
        con.Open();

Open in new window


not sure why....
0
Comment
Question by:yguyon28
2 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 40353122
The backslash is a special character in C# strings. To use it, you need to enter it as two backslashes (\\).
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 40353129
If you don't prefix a C# String with @ all backslashes are the start of an escape sequence for special characters like new line \n or tab \t or many others, but \m is none of them.

Two solutions:
1. The escape sequence for backslash is \\
con = new SqlConnection("Data Source=SVSQ02\\macomb_test;Initial Catalog=DropDown;Integrated Security=True");

2. Tell C# you don't want to use escape sequences in the string with the @ prefix:
con = new SqlConnection(@"Data Source=SVSQ02\macomb_test;Initial Catalog=DropDown;Integrated Security=True");

Bye, Olaf.

Edit: I'm almost sure you've already seen sample code using the @ prefix. It's often the better solution for things like paths, especially unc path starting with "\\\\server\\share" are worse readable than @"\\server\share".
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question