Application.StartupPath and mdb problem

D

Ddraig

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=[b:6e962dc7b3]dbPath[/b:6e962dc7b3];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?
 
C

Cor Ligthert

Ddraig,

I have send this message this morning to Barkster (and when you see there he
showed that it did work for him)

I can let you search, however I copied it.

I have strugled a longtime with this and it is so easy, just set in the load
event from your form (or whatever place, before the connection object is
used however after that it is initialized) using the connection object you
have created with the designer (and don't change that in the designer
generated code) the connection string.

Someting as
OleDBConnection1.connectionstring = "xxxxxxxxxxxxx" & applicationstartuppath

Mostly those connection strings do not have that difficult as build with the
designer, have a look at these links for them.

http://www.connectionstrings.com/

http://www.able-consulting.com/ADO_Conn.htm

I hope this helps?

Cor
 
D

Ddraig

Thanks for the help :) I was able to figure it out it was a problem
with the silly " marks they always get me. :roll:
 

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