简体   繁体   中英

how to publish C# application with the access database

I created a C# application which run with Microsoft Access database and after I deployed the project and installed it on C drive the database file becomes read only, and, if I install it on D or another drive it works fine.

Please if any one can help it is appreciated (SIS is access database file) the problem is i want to make it work in C drive also.

这是我的设置SIS是访问文件 this is my setup SIS is the access file

And this is the connection string im using

String cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\SIS_DB.accdb;";

You are old school ... the C drive these days is forbidden area.

Use either the Program Data folder for application specific data - or, for user data, the %AppData% folder where you create a folder for your application and use this folder for the user's data.

Your problem is your database file is in %ProgramFiles%. It should be in %AppData%

There are two ways to resolve

1.modify the setup project. when you make the setup,you should specify the path of f.mdf,ensure that the file will install into AppData folder.

2.copy f.mdf to AppData folder by app. every time you run you app,the first thing is to copy the file to AppData folder, you can add the follow code in your Main(or init) method and try again:

string sourcePath=@"C:\PROGRAM FILES\DEFAULT COMPANY NAME\SETUPER2";
string appDataPath= Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string fileName="F.MDF";
System.IO.File.Copy(sourcePath+"\\"+fileName, appDataPath+"\\"+fileName ,false);

*1 is better.

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