简体   繁体   中英

Connection string to access database in Program files

I am working on windows form which uses microsoft access database.

When the application will be installed, the database will be on this location C:\\Program Files (x86)\\Amrit\\trial\\Database.

How can i make this work so that this application will linked to the database when installed in my computer.

Can somebody give me easy solution.. Currently my connection string looks like this..

string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Amrit\\Desktop\\Database.accdb ;Persist Security Info=False;";

when i create setup file for appplication, the database will be in ProgramFiles/AmritCreations/AppName/Database.accdb

在此处输入图片说明

Just place your database and your application in the same directory and use this connectionString

string connString = "Provider=MICROSOFT.ACE.OLEDB.12.0; " +
                    "Data Source=|DataDirectory|/Database.accdb";

In times you're creating a Setup Project , try to place the database file and [yourProjectName].exe in the same directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM