Connection String Problem

B

bob

Hi,

I am trying to encrypt my connection string in the app.config file. I am
using Base64 encryption, I just want to hide it from casual users. I keep
getting file not found error. However when I just use the connection string
in plain text I can connect fine. The only difference between the two is
the @ sign is used in front of the connection string (plain) when I view
them in the command window (see below). Any ideas?
? this.connectionString
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\WINDOWS\\system32\csdm.dll;Jet OLEDB:Database Password=passwd;"
? this.connectionString
@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\WINDOWS\\system32\csdm.dll;Jet OLEDB:Database Password=passwd;"
 
N

Norman Yuan

If your string value is prefixed with "@", you do not have to escape "\" by
doubling it.
So, in your first connectionString, yo need double "\" after "system32"; in
your second connectionString, you unnecessarily doubled "\", so that I do
not believe the file path is correct. Thus, both are wrong.

BTW, is "csdm.dll" is a valid Jet data source file? never heard of.
 
W

W.G. Ryan - MVP

Bob - which one is failing, the one with the @ or the other one? Either way
though, I used the same connection string using a *.mdb extension and didn't
have a problem. Before the call to open the connection or fill with the
adapter, use a Debug.Assert(File.Exists(@"C:\\WINDOWS\\system32\csdm.dll"),
"The File doesn't exist"); and verify that it can be seen. If it works
though with the only difference, that's probably not the problem

If the one with the @ symbol works, then that's to be expected, however if
it's the one that doesn't, then that's curious. C# uses the \ as an escape
so if you tried using the output from the command window there without the @
directly, then it wouldn't compile. You could just take that string and
append the @ at the beginning and you should be good to go, but if the
problem is the reverse than i'm getting a little ahead of myself.
 
S

scorpion53061

If you are using 1.1 still let me know. I will help you encrypt it and
store and read it from an XML file.

Kelly
 
C

Cor Ligthert [MVP]

Bob,

If you add the @ "what is a C# compiler directive" add to the
connectionstring of your connection that you are than are in trouble. I have
the idea that you do that at runtime accoording to your description.

Cor
 
C

Cor Ligthert [MVP]

Bob,

To bad text I have probably to often changed that see here my correction.

If you add the @ "what is a C# compiler directive" to your connectionstring
of your connection object, than you are in trouble. I have the idea that you
do that at runtime accoording to your description.

Cor
 

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