Setting the ConnectionString at StartUp

D

Didymus

Hi everyone,

How would I adjust the following ConnectionString to point to the
applications installed path?
===
Provider=Microsoft.Jet.OLEDB.4.0;Password="";User ID=Admin;Data Source=SOME
DRIVE\SOME DIRECTORY\THE DATABASE;Mode=Share Deny None;Extended
Properties="";Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet
OLEDB:Database Password="";Jet OLEDB:Engine Type=5;Jet OLEDB:Database
Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk
Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System
Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale
on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet
OLEDB:SFP=False
===

I want the user to be able to install the application wherever they want,
and I need the ConnectionString to point to that location.
I have no problem getting the Application.StartupPath.
I have tried to split the ConnectionString into two seperate strings and
concatenate the strings and Application.Path together, but it doesn't seem
to work.

This is what I have tried...
It seems to mess up the DoubleQuotes in the strings.

///
Dim AppPath As String = Application.StartupPath

Dim conString1 As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Password="";User ID=Admin;Data Source="

Dim conString2 As String = "\THE DATABASE;Mode=Share Deny None;Extended
Properties="";Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet
OLEDB:Database Password="";Jet OLEDB:Engine Type=5;Jet OLEDB:Database
Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk
Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System
Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale
on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet
OLEDB:SFP=False"

Dim conString As String = conString1 & AppPath & conString2
///

Thanks in advance,

Gary
 
R

Richard Ryerson

Try using reflection

I believe its System.Reflection.Assembly.GetExecutingAssembly.Location

That is the full path and file name of the executing assembly (your
application in this case)

Try looking at the other "Get" methods in the assembly class.

-Rick
 
D

Didymus

Thanks,

But...
System.Reflection.Assembly.GetExecutingAssembly.Location
.... gives "C:\Some Folder\Some Other Folder\etc\Application.exe"

....
Application.StartupPath
.... gives "C:\Some Folder\Some Other Folder\etc\"
which is what I want.

My trouble is joining the Strings together...

String1 and String2 have some values with two double quotations ("") in
them.
When I declare the two strings...
....Public String1 As String = "Some text string with "" in it\"
....Public String2 As String = "Some other string with "" in it"
.... AppPath As String = Application.StartupPath
.... String3 = String1 & AppPath & String2

I get... String3 = "Some text string with " in it\C:\Some Folder\Some Other
Folder\etc\Some other string with " in it"

Notice that the double quotes get reduced to one single quote (").

If I remove the portions with the double quotes, it works fine, however, I
may need the double quotes at a later time.

Thanks,

Gary
 
C

Charlie Smith

My trouble is joining the Strings together...
Gary,

If you need to add a double quote to the string, try using (chr)34.

Charlie
 
D

Didymus

Thanks Charlie,

I knew it would be something silly, just couldn't put my finger on it...
lol

Gary
 

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