In my Visual Basic Application, I have an access database file that I am using. It shows up in the solution explorer window. Everything works great until I install. The database file doesn't go with the installation for some reason. I guess I need to edit the connection string during runtime, but I am not sure. I have not done anything like this before, and I cannot find the information about it.
If someone could send me to a tutorial or give a brief explanation of how to use an access database once the application has been installed.
When my program runs, it creates a directory in
User\App Data\Roaming\CreatedFolder\Resources\DatabaseFile.accdb
So how do I set this path without knowing the full path up to App Data?
The way I would do this would be to:
Add New Data Source . . .
from the Data Source window in Visual StudioDatabase
from the list that appears, and click nextChoose your data connection
page of the wizard, clickNew connection
Microsoft Access Database File
from the listbox and click nextNow Visual Studio will ask you:
The connection you selected uses a local data file that is not in the current project. Would you like to copy the file to the project and and modify the connection?
If you copy the data file to your project, it will be copied to the project's output directory every time you run the application. Press F1 for information on controlling this behavior.
Click "Yes," and Visual Studio will add the database to your project and make a connection string that points to the copied database.
|DataDirectory|
. Modify the contents of this page as you see fit.The wizard should configure the connection string and build information such that your application will work no matter where you take it.
EDIT - My connection string as it is saved in App.config looks like
I also have the database file's Build Action set to "Copy Always."
You can use
or
They both should return something similar to
so you can build your connection string like this: