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]
# 1 Re: Datafile Path
App.Path ;)

HTH,
Krzemo.
Krzemo at 2007-11-9 13:44:52 >
# 2 Re: Datafile Path
Hi Krzemo,

Vb intellisense didn't recognize "App.Path" keyword. How do you use it in my case? Please advise. Tks.

mariposo
mariposo at 2007-11-9 13:45:52 >
# 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"
Mitsukai at 2007-11-9 13:46:52 >
# 4 Re: Datafile Path
I think you use vb.net
Try Application.StartupPath
hspc at 2007-11-9 13:47:57 >
# 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.
mariposo at 2007-11-9 13:48:57 >
# 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.
mariposo at 2007-11-9 13:49:57 >
# 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 >
# 8 Re: Datafile Path
Thanks to all for the tips.

I will use application.startup with a little twist on my part.

mariposo
mariposo at 2007-11-9 13:51:54 >