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?
You can use
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
or
Environment.GetEnvironmentVariable("APPDATA")
They both should return something similar to
C:\Users\Gord\AppData\Roaming
so you can build your connection string like this:
Dim dbPath = _
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & _
"\CreatedFolder\Resources\DatabaseFile.accdb"
Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With