Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application.StartupPath and mdb

Status
Not open for further replies.

Ddraig

MIS
Jul 16, 2004
97
US
Howdy,

I've spent a good 2 or 3 hours this morning trying to figure out this code. I'm new to the .Net environment and have some VB6 skills but that was 3 years ago.

My project I'm working on accesses a Access DB to pull in data. I used the designer to pull in the components I needed to connect to the database.

Here is my Code:

Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=""C:\Owens\Visual Studio Projects\Tailoring\bin\tailori" & _
"ng.mdb"";Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLE" & _
"DB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=Fal" & _
"se;Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB" & _
":Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't C" & _
"opy Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"

I think this is a bit over kill, but what I'm trying to do is get it so that I can put in the relative path to the database instead of literal. However, when I change the datasource path it gives me an error with my dataset.

Example of that code here:

Dim dbPath as String = Application.StartupPath & "\tailoring.mdb"

Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=dbPath;Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLE" & _
"DB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=Fal" & _
"se;Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB" & _
":Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't C" & _
"opy Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"

This is the Error I get when I attempt to run it with that code.

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

Code for that line is: OleDbDataAdapter1.Fill(DataSet1)

Anyone have any suggestions?
 
Try this code, your dbpath is text not the variable.

Dim dbPath as String = Application.StartupPath & "\tailoring.mdb"

Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=" & dbPath & ";Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLE" & _
"DB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=Fal" & _
"se;Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB" & _
":Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't C" & _
"opy Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
 
actually use this (need the quotes still):

Data Source=""" & dbPath & """;Mode=Share.....

instead of Data Source=" & dbPath & ";Mode=Share.....
 
Ahh Sweet! I knew my problem was with trying to figure out the quotes, their were so many of them it wasn't looking right.

Thanks for the help looks like it will work now :)
 
Thanks for this post. I modified it slighly to work with my dataconnection.

Dim dbPath As String = "\DublinFundRaising\DublinFundRaising.mdb"

AS a follow up, How can i setup a function so a user of this program can later change the database location??

I believe i need to find a way to modify this with the use of a textbox or something.

Dim dbPath As string "\DublinFundRaising\DublinFundRaising.mdb"


MY CODE THAT NOW WORKS
Dim dbPath As String = "\DublinFundRaising\DublinFundRaising.mdb"

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=""" & dbPath & """;Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Tran" & _
"sactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLE" & _
"DB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Pa" & _
"ssword=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Co" & _
"mpact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLE" & _
"DB:Encrypt Database=False"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top