Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy an access database file with my application?

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?

like image 452
xRuhRohx Avatar asked Sep 23 '14 12:09

xRuhRohx


1 Answers

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
like image 117
Gord Thompson Avatar answered Oct 01 '22 00:10

Gord Thompson