Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

unrecognized escape sentence - Connection string

Posted on 2014-09-30
2
Medium Priority
?
156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
Shaun Kline earned 2000 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 30

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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