|
-
Sep 5th, 2011, 04:00 AM
#1
Thread Starter
New Member
Database Path Error
Dears,
I have done a windows application VB.NET with access Database. while working on it, i had the database path
Code:
Private ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\LBCvehicles.mdb;Persist Security Info=True"
But since i wanted to deploy this project and install it on another pc i dint want the DB file to stay on C so i added a new folder to my project "DB" and added to it the access file.
Code:
Private ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= .\DB\LBCvehicles.mdb;Persist Security Info=True"
and i tried it before deployment everything worked fine.
I deployed the application and when running the setup file i got the following error :
"The folder path'.' contains an invalid character"
Please i need your help !
-
Sep 5th, 2011, 04:57 AM
#2
Re: Database Path Error
You're actually making things harder for yourself. All the support you need is already built into VB. Simply add the original data file to your project and, if prompted consent to copying it into your project folder. You can now basically forget the original data file and just work with the source data file that you'll now find in your project folder, along with all your other source files.
Each time you build your project, the source data file is copied and the copy is placed in the output folder, along with your EXE and any other output files. It's that copy that your application should connect to at run time. When you build a release version, it's the copy in the Release output folder that you deploy with your app. Because the deployed database is a copy of the original source, which has never been touched by the app during testing/debugging, it remains clean.
In your connection string, you use the |DataDirectory| place-holder for the folder path, e.g.
Code:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\LBCvehicles.mdb;
That way it doesn't matter where your app is (debugging in VS/VB, deployed on your own machine, deployed to a user's machine) or how it's deployed (XCOPY, ClickOnce, Windows Installer), it will just work. If you want to put the database in a specific location then you can add code to the app's Startup event handler to change the data directory.
You may like to follow the first link in my signature for the official explanation.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|