472,805 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

How Do I "Escape" A SQL Connect String With Non-Standard Server Name?

Hello!

I am trying to connect to a SQL Server (MSDE) database in mixed mode
authentication, via C#, but when I use the MSDE instance name, I keep
getting an "Unrecognized Escape Sequence" error. The Data Source name
has a backslash in it, and I'm guessing that this is causing the
problem. How do I "Escape" the name, to make this work? I'm able to
connnect in the .NET developement platform (Tools / Connect To
Database), etc, using the full MSDE instance name, ie,
SWC_K7\CHRISMON1, but when I call that from code, the compiler catches
it as an error.

Connect String:

conn = new SqlConnection("Data Source=SWC_K7\CHRISMON1;
User Id=yadda;
password=yadda;
Initial Catalog=ChrismonContacts");

Thanks!

Steven
Nov 16 '05 #1
5 8041
Steven C wrote:
conn = new SqlConnection("Data Source=SWC_K7\CHRISMON1;


Add the "add" character in front of the string:

conn = new SqlConnection(@"Data Source=SWC_K7\CHRISMON1;

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
Nov 16 '05 #2
Steven:

In C#, using the "@" symbol in front of a string wills escape it. There are
many other instances, particularly when dealing with Paths, Files, Regular
Expressions that this is very handy. You can either replace each single
instance of "\" with "\\" or use the @ Symbol: conn = @"Data
Source=SWC_K7\CHRISMON1;User Id=yadda; password=yadda;
Initial Catalog=ChrismonContacts");

<Steven C> wrote in message
news:ld********************************@4ax.com...
Hello!

I am trying to connect to a SQL Server (MSDE) database in mixed mode
authentication, via C#, but when I use the MSDE instance name, I keep
getting an "Unrecognized Escape Sequence" error. The Data Source name
has a backslash in it, and I'm guessing that this is causing the
problem. How do I "Escape" the name, to make this work? I'm able to
connnect in the .NET developement platform (Tools / Connect To
Database), etc, using the full MSDE instance name, ie,
SWC_K7\CHRISMON1, but when I call that from code, the compiler catches
it as an error.

Connect String:

conn = new SqlConnection("Data Source=SWC_K7\CHRISMON1;
User Id=yadda;
password=yadda;
Initial Catalog=ChrismonContacts");

Thanks!

Steven

Nov 16 '05 #3
The backslash is the escape character. Type "SWC_K7\\CHRISMON1" in the
connection string.
<Steven C> wrote in message
news:ld********************************@4ax.com...
Hello!

I am trying to connect to a SQL Server (MSDE) database in mixed mode
authentication, via C#, but when I use the MSDE instance name, I keep
getting an "Unrecognized Escape Sequence" error. The Data Source name
has a backslash in it, and I'm guessing that this is causing the
problem. How do I "Escape" the name, to make this work? I'm able to
connnect in the .NET developement platform (Tools / Connect To
Database), etc, using the full MSDE instance name, ie,
SWC_K7\CHRISMON1, but when I call that from code, the compiler catches
it as an error.

Connect String:

conn = new SqlConnection("Data Source=SWC_K7\CHRISMON1;
User Id=yadda;
password=yadda;
Initial Catalog=ChrismonContacts");

Thanks!

Steven

Nov 16 '05 #4
<Steven C <>> wrote:
I am trying to connect to a SQL Server (MSDE) database in mixed mode
authentication, via C#, but when I use the MSDE instance name, I keep
getting an "Unrecognized Escape Sequence" error.


See

http://www.pobox.com/~skeet/csharp/faq/#escapes
and
http://www.pobox.com/~skeet/csharp/f...batim.literals

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Awesome!

This worked.

Thanks, gentlemen

Steven C
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: /dev/null | last post by:
Is there a function in php that you can pass a string headed for a mysql query and have it make it 'safe'? For example it would escape out the ' found in the string. Thanks!
11
by: Dave Smithz | last post by:
Having adopted someone else's PHP cope and completing a crash course in the language I came across a (probably common) problem with the current code. On a registration form, whenever users names...
0
by: Lyn | last post by:
We use response.redirect to connect to an external web site which does not work when the "=" sign is translated to "%3B" and the ";" to "%3D". Is there a way to turn this default translation off?...
1
by: Lyn | last post by:
We use response.redirect to connect to an external web site which does not work when the "=" sign is translated to "%3B" and the ";" to "%3D". Is there a way to turn this default translation off?...
7
by: ryan.fairchild | last post by:
Ok I basically am creating a container for a bunch of other <div> tags. But I want to make four jpegs/gif/whatever that goes in each corner so they look rounded. I thought this is how I would do...
4
by: Peter | last post by:
Hi: How could I escape "{" in Console.Write(), i.e. I want output like -- { 1234 }, how could I do it in one Console.Write()? thx.
5
by: Prince Kumar | last post by:
I am trying to escape the special characters while executing the following sql, but couldn't figure out a way. db2_all "db2 connect to mydb; db2 select * from table (SNAPSHOT_CONTAINER ( '' , -1...
2
by: Tim Marshall | last post by:
What is the docmd.runcommand accmd? for the equivalent of pressing the escape button when adding a record to a table? I'm setting up a bound form and would like to have a "cancel" button that...
0
by: YiFai | last post by:
Hello, I'm currently writing a directx program with C++, but it takes a while to load the files necessary for the directx. When the directx window loads, it can quit the program with the...
0
by: Jeff Groves | last post by:
I'm using FreezePython on a Python program that uses wxPython and subprocess. The result almost works, but it always hits this bug: File "velauncher.py", line 847, in Launch File...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.