OLEDBConnection

  • Thread starter Thread starter David A. Osborn
  • Start date Start date
D

David A. Osborn

Is there a way to make the OLEDBConnection to my Access file relative to the
path of the executable of the file? I work on the program on a lot of
different computers and I am tired of having to copy things around so that
the Access file is in the right path.
 
As a follow up, is there then a safe way to change what ever I need to
change so that my data adapter, dataset and data bindings don't get
completely screwed up.
 
David said:
Is there a way to make the OLEDBConnection to my Access file relative to the
path of the executable of the file? I work on the program on a lot of
different computers and I am tired of having to copy things around so that
the Access file is in the right path.

For standard security

oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\somepath\myDb.mdb;"

If using a Workgroup (System Database)

oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Application.Startup & "\somepath\mydb.mdb;"
& _
"Jet OLEDB:System Database=MySystem.mdw", _
"myUsername", "myPassword"

Note, remember to convert both the MDB and the MDW to the 4.0
database format when using the 4.0 OLE DB Provider.


If MDB has a database password

oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Application.Startup & "\somepath\mydb.mdb;"
& _
"Jet OLEDB:Database Password=MyDbPassword", _
"myUsername", "myPassword"


If want to open up the MDB exclusively

oConn.Mode = adModeShareExclusive
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Application.Startup & "\somepath\mydb.mdb;"
 
I was confused by your comment;
"Note, remember to convert both the MDB and the MDW to the 4.0
database format when using the 4.0 OLE DB Provider"
I use an Access Database (.mdb extension) but was not aware of the mdw
extension nor the nead to convert to anything. I also use the 4.0 OLE DB
Provider and haven't had to convert anything.

Could you explain a bit more...thanks for you comments.
 
David,

Probably you use a dragged connection.

Than just set the connection in by instance the form load of your program,
however before the open of the connection.

Don't delete the dragged connection from the designer part, because that can
give you all kind of trouble.

Connection1 = New Connection(And than the connection string you want)

That string you can save in an XML or Ini or whatever file.

I hope this helps,

Cor
 
¤ Is there a way to make the OLEDBConnection to my Access file relative to the
¤ path of the executable of the file? I work on the program on a lot of
¤ different computers and I am tired of having to copy things around so that
¤ the Access file is in the right path.
¤
¤

There are a few ways to fetch the application path one of which is Application.StartupPath.


Paul
~~~~
Microsoft MVP (Visual Basic)
 

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

Back
Top