Question Connection string data source relative path

Saeros3

Member
Joined
Aug 19, 2009
Messages
9
Programming Experience
1-3
hi,
I have an MS Access database and i'm trying to connect to it in vb .net.
My question: Is there a way to provide a relative path to a database in the connection string?
the problem is that when I move the db and app, the path is no longer valid.
I read something about using "|DataDirectory|" in the path, but they didn't elaborate on that and i haven't found any more information.
 
Last edited:
Read the DW2 link in my signature, section Creating a Simple Data App

When you are done with the steps, look in the project settings.. the conenction string will contain a |DataDirectory| specifier
 
You can have the database in the same folder as your program, then use Application.StartUpPath. Eg. Constr="PROVIDER=Microsoft.Jet.OleDB.4.0; Data Source=" &Application.StartUpPath & "/" & " database.mdb"
 
You can have the database in the same folder as your program, then use Application.StartUpPath. Eg. Constr="PROVIDER=Microsoft.Jet.OleDB.4.0; Data Source=" &Application.StartUpPath & "/" & " database.mdb"
By default, |DataDirectory| will resolve to the same folder as Application.StartupPath and you can code it right into the literal connection string rather than using code, so it is a preferable choice.
 
By default, |DataDirectory| will resolve to the same folder as Application.StartupPath and you can code it right into the literal connection string rather than using code, so it is a preferable choice.

Thanks for the heads up, i didnt know about that.
 
Back
Top