may be escape chars related?

A

abcd

Case 1


I have a variable called sConnectString whose value is [ I dynamically
generate sConnectString from the database values, so can not hardcode]

"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 following thing it works fine (note here escape characters
are hard coded in the hard coded string)

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

OleDbConnection myConnection = new OleDbConnection(ss );

myConnection.Open();




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

any thoughts
 
B

Bob Grommes

Why don't you simply do this:

OleDbConnection myConnection = new
OleDbConnection(sConnectString.Replace(@"\",@"\\"));

That's assuming sConnectString, as generated, actually contains any
slashes what you think it does in the first place. The problem may be
in how you are generating it; it's possible that every backslash is
being interpreted somewhere along the line as an escape character and
you don't have the connection string you think you do. (Remember that
the debugger may be displaying literally what's in the string or it may
be displaying escape characters).

--Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top