Solved

unrecognized escape sentence - Connection string

Posted on 2014-09-30
2
136 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 25

Accepted Solution

by:
Shaun Kline earned 500 total points
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now