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

RE: OleDbConnection String Help

P: n/a
Perry,

Application.StartupPath gives you the location of the exe file. This is
where the database is assumed to be located if you don't say otherwise.

If your database is in a folder named Database that is a subfolder of the
folder where your exe file is located then you should be able to do this:

Data Source=Database\Database.mdb

Kerry Moorman

"Perry Langla" wrote:
What I am trying to do is get the directory information of the executing
assembly and insert this information into the ConnectionString. Here is an
example of what I have so far;

' I am using reflection to find the location of the exe file. This is
because the directory
'for the database is located in the same directory.

Dim Asm As System.Reflection.Assembly =
System.Reflection.Assembly.GetExecutingAssembly
Dim strEXELoc As String
strEXELoc = Asm.Location

' I am now putting the information into the string.

Dim strTemp As String
strTemp = strEXELoc
strTemp = System.IO.Path.GetDirectoryName(strEXELoc)

Dim DatabaseInfo As String
DatabaseInfo = strTemp
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data Source=""C:\Program
Files\Company" & _
"\Program\Database\Database.mdb"";Jet OLED" & _
"B:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet
OLEDB:System database=;Je" & _
"t OLEDB:SFP=False;Jet OLEDB:Global Bulk Transactions=1;Mode=Share
Deny None;Jet " & _
"OLEDB:New Database Password=;Jet OLEDB:Create System
Database=False;Jet OLEDB:Do" & _
"n't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;" & _
"User ID=Admin;Jet OLEDB:Encrypt Database=False"
I am trying to get the Data Source to read Data Source=""Default
Drive:\ExecutingAssembly Location\Database\Database.mdb""
Please help. I think I am on the right track.

Thanks Perry
Sep 23 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Thanks Kerry
The solution works.
Sometimes I over analize things.

"Kerry Moorman" <Ke**********@discussions.microsoft.comwrote in message
news:65**********************************@microsof t.com...
Perry,

Application.StartupPath gives you the location of the exe file. This is
where the database is assumed to be located if you don't say otherwise.

If your database is in a folder named Database that is a subfolder of the
folder where your exe file is located then you should be able to do this:

Data Source=Database\Database.mdb

Kerry Moorman

"Perry Langla" wrote:
>What I am trying to do is get the directory information of the executing
assembly and insert this information into the ConnectionString. Here is
an
example of what I have so far;

' I am using reflection to find the location of the exe file. This is
because the directory
'for the database is located in the same directory.

Dim Asm As System.Reflection.Assembly =
System.Reflection.Assembly.GetExecutingAssembly
Dim strEXELoc As String
strEXELoc = Asm.Location

' I am now putting the information into the string.

Dim strTemp As String
strTemp = strEXELoc
strTemp = System.IO.Path.GetDirectoryName(strEXELoc)

Dim DatabaseInfo As String
DatabaseInfo = strTemp
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data
Source=""C:\Program
Files\Company" & _
"\Program\Database\Database.mdb"";Jet OLED" & _
"B:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet
OLEDB:System database=;Je" & _
"t OLEDB:SFP=False;Jet OLEDB:Global Bulk
Transactions=1;Mode=Share
Deny None;Jet " & _
"OLEDB:New Database Password=;Jet OLEDB:Create System
Database=False;Jet OLEDB:Do" & _
"n't Copy Locale on Compact=False;Jet OLEDB:Compact Without
Replica
Repair=False;" & _
"User ID=Admin;Jet OLEDB:Encrypt Database=False"
I am trying to get the Data Source to read Data Source=""Default
Drive:\ExecutingAssembly Location\Database\Database.mdb""
Please help. I think I am on the right track.

Thanks Perry
Sep 24 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.