Setting Oledbconnection datasouce path

  • Thread starter Thread starter Bob Achgill
  • Start date Start date
B

Bob Achgill

I would like to set the DataSource path on my
Oledbconnection so that the Windows application will
always look in the place where the binary is stored when
it looks for the Access database file. How can this be
done?

I tried sticking the function CurDir() into the property
string but I don't seem to be getting the syntax right.
Here is the connection string that I am trying to modify.

====================

Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry
Path=;Jet OLEDB:Database Locking Mode=1;Jet
OLEDB:Database Password=;Data Source="C:\Documents and
Settings\Bob\My Documents\Visual Studio Projects\GoHands1
\GoHands1\bin\godanddeaf.mdb";Password=;Jet OLEDB:Engine
Type=5;Jet OLEDB:Global Bulk
Transactions=1;Provider="Microsoft.Jet.OLEDB.4.0";Jet
OLEDB:System database=;Jet OLEDB:SFP=False;Extended
Properties=;Mode=Share Deny None;Jet OLEDB:New Database
Password=;Jet OLEDB:Create System Database=False;Jet
OLEDB:Don't Copy Locale on Compact=False;Jet
OLEDB:Compact Without Replica Repair=False;User
ID=Admin;Jet OLEDB:Encrypt Database=False
 
Hi Bob,

You can create a new connection in your form load event, that works, I have
a long time searched for that however it is really that simple.

I hope this helps, if it is not clear be free to ask again?

Cor
 
OK.

I tried putting the new connection in the Form Load event
but I still seem to not know how to properly write the
string with the Curdir() function embedded with in.
Still a novice at this programming stuff.

Here is what I tried and the resulting error...

Private Sub Form1_Load(ByVal sender As Object, ByVal e
As System.EventArgs) Handles MyBase.Load

'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=" + CurDir() + "\godanddeaf.mdb"";" & _
"Password=;Jet OLEDB:Engine Type=5;Jet
OLEDB:Global Bulk Transactions=1;Provider=" & _
"""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System
database=;Jet OLEDB:SFP=False;Extende" & _
"d Properties=;Mode=Share Deny None;Jet OLEDB:New
Database Password=;Jet OLEDB:Cr" & _
"eate System Database=False;Jet OLEDB:Don't Copy
Locale on Compact=False;Jet OLED" & _
"B:Compact Without Replica Repair=False;User
ID=Admin;Jet OLEDB:Encrypt Database=" & _
"False"



Error -
Additional information: Format of the initialization
string does not conform to specification starting at
index 263.
 
Hi Bob,

I assume that that long connection string is not needed, mostly this is
enough and than I initialize the connection as new however when I write this
now I am in doubt if it is necessary, however I always do it this way, maybe
only adding that connectionstring is enough, because logical it should be
that.

dim connString as string = Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\myaccessfile.mdb;
Oledbconnection1 = New OleDbConnection(connString)

I hope this helps?


Cor
 
Bob Achgill said:
OK.

I tried putting the new connection in the Form Load event
but I still seem to not know how to properly write the
string with the Curdir() function embedded with in.
Still a novice at this programming stuff.


Hello Bob,

In your form_load event change the datasource to just the name of your .mdb
file.

"Data Source = mydatabase.mdb"

There is no need to use the curdir() function just use the relative path in
the form load event.

HTH
 
Back
Top