Application refers to files on other C-Drive

JohnM

Well-known member
Joined
Jul 2, 2004
Messages
116
Location
Massachusetts
Programming Experience
1-3
Hi,
I created an application, created the installer, ran the installer on the client PC.
The application starts ok, but when it goes to the first page that has a datagrid with information, it crashes with the error message that the path to the MDB isn't valid. The path listed is the path to the mdb on the PC that I created the application on. I have alot of images on this application, but it doesn't have a problem finding those. Why doesn't it look for the mdb's like it looks for the images?

I appreciate your help.

John M
 

suddenelfilio

Well-known member
Joined
Jun 3, 2004
Messages
144
Location
Belgium
Programming Experience
5-10
I always use reflection. For example: pout the mdb file in the same folder as your executable you are running. Then use the shared method System.Reflection.Assembly.GetExecutingAssembly.location. this will give you the path of the current location put this into a string path then use de substring to get the path without filename and paste the filename from the mdb file

VB.NET:
dim path as string = System.Reflection.assembly.getexecutingassembly.location
path = path.substring(0,path.lastindexof("\") + 1)
path &= "somefile.mdb"
this way your app will always go to the correct folder because this an dynamic function which returns the folder its currently running.

Another solution is using the environment.Getlocalfolder method. have a look at this one also!
 

JohnM

Well-known member
Joined
Jul 2, 2004
Messages
116
Location
Massachusetts
Programming Experience
1-3
Thank you

I read your answer. To do this dynamically is great. I will try it out. I'm new at .Net but I also know that the less work the user has to do the better.
Thanks again for your advice

John M
 

bloukewer

Well-known member
Joined
Jul 2, 2004
Messages
88
Programming Experience
3-5
Another connection-string

Here's another great example:

con1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""" &
Application.StartupPath & _
"\Test.mdb"";"
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
the database is always an external resource in applications, where as images get compiled within the exe file, use application.startuppath when referenceing external objects, like what bloukewer did :)
 
Top Bottom