Relative path to database (newbie)

  • Thread starter Thread starter David Jenkins
  • Start date Start date
D

David Jenkins

I've created a simple application linked to a MS Access
database the problem is the connection is looking for the
database path on my machine so when I install the
application on another machine obviously the path isn't
found and throws an error, how can I set up the
connection path so it will always be picked up regardless
of where its installed (either the installation directory
or the projects bin directory would be fine) ???

Thanks in advance
David
 
the dir the exe file is in (under development this is the bin folder)
application.startuppath
 
untested . . .

have you tried using .\filename or .\pathname\filename ?

OHM


David said:
I've created a simple application linked to a MS Access
database the problem is the connection is looking for the
database path on my machine so when I install the
application on another machine obviously the path isn't
found and throws an error, how can I set up the
connection path so it will always be picked up regardless
of where its installed (either the installation directory
or the projects bin directory would be fine) ???

Thanks in advance
David

Regards - OHM# (e-mail address removed)
 
Actually the .\ and ..\ directory which represent ( current Directory ), and
( Parent Directory ) do work in the connection string so you can use that
with ease. The BIN directory is the default when debugging.

OHM

untested . . .

have you tried using .\filename or .\pathname\filename ?

OHM




Regards - OHM# (e-mail address removed)

Regards - OHM# (e-mail address removed)
 
¤ I've created a simple application linked to a MS Access
¤ database the problem is the connection is looking for the
¤ database path on my machine so when I install the
¤ application on another machine obviously the path isn't
¤ found and throws an error, how can I set up the
¤ connection path so it will always be picked up regardless
¤ of where its installed (either the installation directory
¤ or the projects bin directory would be fine) ???
¤
¤ Thanks in advance
¤ David

If the database path is relative to the location of your application (executable) path then use the
following:

Dim DatabasePath As String

Dim FileInfoPath = New
System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly.Location)

DatabasePath = FileInfoPath.Directory.FullName & "\Database"


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Hi Davix,

How did link your application to the ms-access database?

If you did it with a code connection you can simple do it by using a
fileinfo on the two directorys you are using and then give yourself the
priority which one will be taken first..

When you use a wizard to make the connection, than has till now nobody
answered how to do it.

I hope this helps?

Cor
 
Hi David,

You can do something, put the database in your end "program files"
directory.
It is not nice, but that is the workaround I saw once.

Cor
 
Its OK, you can change the code generated by the wizard, look for the
connection string in the form code. something like this. See where I
modified the code to test what you wanted

con.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Registry Path=;Jet OLEDB:Database L" & _

"ocking Mode=1;Data Source=""..\" & _ '<<< *********
MODIFIED CODE **************

"FamilyPlusFriends.mdb"";Jet OLEDB:Engine
Type=5;Provider=""Microsoft.Jet.OLEDB.4.0" & _

""";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security
info=False;Ext" & _

"ended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet
OLED" & _

"B: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:Global
Bulk T" & _

"ransactions=1"



David said:
Being an amateur I decided to use the connection wizard
so it looks like I'm stuck with the path hard coded as
I've got no idea on how to go about manually coding a
connection thanks for your help anyway

Dave

Regards - OHM# (e-mail address removed)
 
Hi OHM,

I wished it was true, this is one of those rare occasions, that when you
change it in the designeer and you want to try to make one correction with
that wizard (select, dataadapter, dataset whatever), you can start all over
again.

I was one of those who did want to use that wizard, I stopped with that, it
is endless.

Cor
 
The problem with this, as I've found out, is that if you
use a OpenFile control, and you open a file from a
different directory, the relative path from then on
points to the last directory used ( the RestoreDirectory
defaults to false on that control ). So I always use the
apppath & \file.mdb to avoid a broken connection.
 
No this is with the DataConnector, the connector is inlikely to change much.
But yes it is an issue.
Hi OHM,

I wished it was true, this is one of those rare occasions, that when
you change it in the designeer and you want to try to make one
correction with that wizard (select, dataadapter, dataset whatever),
you can start all over again.

I was one of those who did want to use that wizard, I stopped with
that, it is endless.

Cor

Regards - OHM# (e-mail address removed)
 
Back
Top