473,395 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

RE: OleDbConnection String Help

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
1 1643
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Job Lot | last post by:
I have written the following function which returns OleDbConnection object. If global variable g_strDbPath contains an invalid file name or path name the catch block throws an error with...
5
by: Tim Bücker | last post by:
Hello. I am trying to get a connection to MySQL using OleDb but it seems that I am making something wrong. I´ve found this source in the net but it doesn´t work for me: ...
1
by: Matthias Kwiedor | last post by:
Hello! My Application is Multi-Threaded, where i have several threads which get datas and write them to the database, or have to read from the database to compare the datas and make updates if...
0
by: Seth | last post by:
First off, my apologies if this is in the wrong newsgroup, but I hope I'm close enough. I'm trying to do some parsing of a CSV file using OleDbConnection, but for some reason, when I populate my...
1
by: Keith | last post by:
Hi, if have this method in a cs file that connections to a database and returns a datareader to my web form. public OleDbDataReader GetDataReader(string theSQL) { theConn = new...
3
by: Ludvig | last post by:
This Exception is executed when using SQLConnection. OleDbConnection connects fine. System.EnterpriseServices.Platform.Initialize() +503...
5
by: CyberLotus | last post by:
Hi, I've created a web application and through this I want to import Excel data to database. Following is the code that I've written, ...
1
by: Souloron | last post by:
Here what I did: string cmdText = String.Format(("CREATE TABLE {0} (dno int primary key, Sunday char(5), Monday char(5), Tuesday char(5), Wednesday char(5), Thursday char(5),...
1
by: Mel | last post by:
I am performing the same recordset multiple times, just passing different parameters each time. Is there a way to do this more efficiently without having to close and re-open the connection and...
2
by: Mark Rae [MVP] | last post by:
"Roger Withnell" <RogerWithnell@discussions.microsoft.comwrote in message news:9579A956-349D-4D23-B253-4175C2D7AE1F@microsoft.com... For ASP.NET you should use a native .NET data provider...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.