Datafile Path
Hi all,
In my VB windows application, I am trying to connect to an ms-access file which is also placed inside the application directory. Below is my connection string:
Public dbConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Password='';Data Source=DBCALL.mdb"
I don't know how to tell VB to locate the file inside the application directory. I tried to use Server.MapPath but that would only work for asp.net. I wonder if there is a similar function for windows application. Please help.
The directory of the "dbcall.mdb" file is within a very long path and it is not practical to hardcode the path because other people cannot use the same hardcoded path if running on their machine.
mariposo
[775 byte] By [
mariposo] at [2007-11-20 5:28:46]

# 3 Re: Datafile Path
what is vb intellisense LOL
try this
Public dbConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Password='';Data Source=" & app.path & "\DBCALL.mdb"
# 5 Re: Datafile Path
what is vb intellisense LOL
try this
Public dbConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Password='';Data Source=" & app.path & "\DBCALL.mdb"
It gives me a wriggle line underneath the "app". VB Express Edition 05 doesn't recognize it.
# 6 Re: Datafile Path
I think you use vb.net
Try Application.StartupPath
Yes, I also tried it. It gives me the path but also includes the debug directory in it. I had to use substring function to cut off that part. Tks.
# 7 Re: Datafile Path
It gives me a wriggle line underneath the "app". VB Express Edition 05 doesn't recognize it.
app won't work (it works in older versions of VB)
Public dbConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Password='';Data Source=" & Application.StartupPath & "\DBCALL.mdb"
you should also check if Application.StartupPath has a slash "\" at the last character and remove it before putting it in the string.This can heppen if you run the application from the root (C:\ for example)
you can do this check using:
If Not Application.StartupPath.EndsWith("\") Then
...
End If
hspc at 2007-11-9 13:50:50 >
