473,322 Members | 1,614 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,322 software developers and data experts.

esacape sequence

case 1
----------

I have a variable called sConnectString whose value is

"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\msxp102\shared\DBS\db3.mdb;User Id=;Password=;";

after this I call following statements

sConnectString = sConnectString.Replace("\\",\\\\);

OleDbConnection myConnection = new OleDbConnection(sConnectString );

myConnection.Open();

I get error file not found.
Case 2
-----------

Where as if I do follwoing thing it works

ss = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\\\msxp102\\shared\\DBS\\db3.mdb;User Id=;Password=;";

OleDbConnection myConnection = new OleDbConnection(sConnectString );

myConnection.Open();

I dont want to hard code the connection string so case 1 must run....

any thoughts

Nov 19 '05 #1
7 1409
my case 2 syntax is as below

Where as if I do follwoing thing it works

ss = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\\\msxp102\\shared\\DBS\\db3.mdb;User Id=;Password=;";

OleDbConnection myConnection = new OleDbConnection(ss);

this works...I am curious why case 1 does not work


"abcd" <ab**@abcd.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
case 1
----------

I have a variable called sConnectString whose value is

"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\msxp102\shared\DBS\db3.mdb;User Id=;Password=;";

after this I call following statements

sConnectString = sConnectString.Replace("\\",\\\\);

OleDbConnection myConnection = new OleDbConnection(sConnectString );

myConnection.Open();

I get error file not found.
Case 2
-----------

Where as if I do follwoing thing it works

ss = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\\\msxp102\\shared\\DBS\\db3.mdb;User Id=;Password=;";

OleDbConnection myConnection = new OleDbConnection(sConnectString );

myConnection.Open();

I dont want to hard code the connection string so case 1 must run....

any thoughts


Nov 19 '05 #2
Based on the difference between your Case 1 and Case 2, it looks like the
reason is that when you use the Replace method, you are only fixing the
problem for the backslashes at the beginning of the Source. Instead of
replacing "\\" with \\\\, try replacing "\" with \\ using Replace("\",\\).
This will fix all the backslashes in your connection string. Good luck.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"abcd" <ab**@abcd.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
case 1
----------

I have a variable called sConnectString whose value is

"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\msxp102\shared\DBS\db3.mdb;User Id=;Password=;";

after this I call following statements

sConnectString = sConnectString.Replace("\\",\\\\);

OleDbConnection myConnection = new OleDbConnection(sConnectString );

myConnection.Open();

I get error file not found.
Case 2
-----------

Where as if I do follwoing thing it works

ss = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\\\msxp102\\shared\\DBS\\db3.mdb;User Id=;Password=;";

OleDbConnection myConnection = new OleDbConnection(sConnectString );

myConnection.Open();

I dont want to hard code the connection string so case 1 must run....

any thoughts


Nov 19 '05 #3
Yikes!

Try using the @"" style declaration for your strings to avoid some of
this. As in:

string sConnectString = @"Provider=Microsoft.Jet.OLEDB.*4.0;Data
Source=\\msxp102\shared\DBS\db*3.mdb;User Id=;Password=;";

That will preserve the backslashes, and not attempt to use them to
initiate escape sequences. As a worst case, at least your replacement
code would be a touch more readable:

sConnectString = sConnectString.Replace(@"\",@"*\\");
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #4
Really frustrating now.

I tried this

sConnectString = sConnectString.Replace(@"\",@"\\");

this fails..

Whereas if I hardcode the same string as

ss= "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\msxp102\shared\DBS\db3.mdb;User Id=;Password=;";

OleDbConnection myConnection = new OleDbConnection(ss);
myConnection.Open();

Connection opens..

I checked sConnectString and ss are exactly same. The only difference is
sConnectString is created dynamically by getting some variables whereas ss
is hardcoded..


jasonkester wrote:
Yikes!

Try using the @"" style declaration for your strings to avoid some of
this. As in:

string sConnectString = @"Provider=Microsoft.Jet.OLEDB.*4.0;Data
Source=\\msxp102\shared\DBS\db*3.mdb;User Id=;Password=;";

That will preserve the backslashes, and not attempt to use them to
initiate escape sequences. As a worst case, at least your replacement
code would be a touch more readable:

sConnectString = sConnectString.Replace(@"\",@"*\\");
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #5
You've lost me. Why exactly are you attempting to replace backslashes
with doubled backslashes?

If you always use @"string" syntax, you won't need to deal with
escaping your slashes. You can concatonate away to your heart's
delight, so long as every element of your string is declared as
@"my\path" rather than "my\path".

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #6
I have variable which value is that long connection string ....

How can I put @ sign for that variable

jasonkester wrote:
You've lost me. Why exactly are you attempting to replace backslashes
with doubled backslashes?

If you always use @"string" syntax, you won't need to deal with
escaping your slashes. You can concatonate away to your heart's
delight, so long as every element of your string is declared as
@"my\path" rather than "my\path".

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #7
Jason pls ignore my earlier email. You are right. I just put @ in front of
my connection string variable and its working

OleDbConnection myConnection = new OleDbConnection(@sConnectString);
myConnection.Open();

thanks

abcd wrote:
I have variable which value is that long connection string ....

How can I put @ sign for that variable

jasonkester wrote:
You've lost me. Why exactly are you attempting to replace
backslashes with doubled backslashes?

If you always use @"string" syntax, you won't need to deal with
escaping your slashes. You can concatonate away to your heart's
delight, so long as every element of your string is declared as
@"my\path" rather than "my\path".

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #8

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

Similar topics

10
by: Anthony Best | last post by:
I'm working on an idea that uses sequences. I'm going to create a table like this: id serial, sequence int, keyword varchar(32), text text for every keyword there will be a uniq sequence...
5
by: Eric E | last post by:
Hi, I have a question about sequences. I need a field to have values with no holes in the sequence. However, the values do not need to be in order. My users will draw a number or numbers from...
1
by: Marek Lewczuk | last post by:
Hello, I would like to ask if my problem with sequence is a proper behavior or this is a bug (probably not)... I have a table: CREATE TABLE "testtable" ( "serialfield" SERIAL,...
3
by: kevin | last post by:
Is that even possible? I am creating a web service in .NET to expose some already created .NET programs to other groups. One group is writing the client in PERL, and thus wishes the wsdl schema...
8
by: regis | last post by:
Greetings, about scanf matching nonempty sequences using the "%" matches a nonempty sequence of anything except '-' "%" matches a nonempty sequence of anything except ']" matches a nonempty...
3
by: Daniel Wilson | last post by:
I am trying to read data from MS SQL Server and turn it into an XML message to send to a remote server, as follows. sfSchemaFileDiag.FilterIndex = 2 If sfSchemaFileDiag.ShowDialog =...
14
by: pat270881 | last post by:
hello, I have to implement a sequence class, however the header file is predefined class sequence { public: // TYPEDEFS and MEMBER CONSTANTS
6
by: Defcon2030 | last post by:
<bHey, can someone help me with this? I've been working on it for a few days now, and my head's starting to spin... </b> // FILE:ex1_imp.cxx // // // // CLASS IMPLEMENTED: sequence (see ex1.h...
1
davydany
by: davydany | last post by:
Hey guys...a n00b Here for this site. I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the...
5
by: Anan18 | last post by:
Hello sir, I'm supposed to Implement and Test the sequence Class Using a Fixed-Sized Array (Chapter 3), from Data Structures & Other objects using c++. The header file is provided, and so is a test...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.