By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,680 Members | 1,578 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,680 IT Pros & Developers. It's quick & easy.

Setting the ConnectionString at StartUp

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Try using reflection

I believe its System.Reflection.Assembly.GetExecutingAssembly.Lo cation

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

"Didymus" <di************@hotmail.com> wrote in message
news:#z**************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #2

P: n/a
Thanks,

But...
System.Reflection.Assembly.GetExecutingAssembly.Lo cation
.... 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
Nov 20 '05 #3

P: n/a
> My trouble is joining the Strings together...


Gary,

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

Charlie
Nov 20 '05 #4

P: n/a
Thanks Charlie,

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

Gary
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.