473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 8080
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.