简体   繁体   English

如何使用访问数据库发布C#应用程序

[英]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. 我创建了一个C#应用程序,该应用程序与Microsoft Access数据库一起运行,并且在部署项目并将其安装在C驱动器上之后,数据库文件变为只读,并且,如果将其安装在D或其他驱动器上,它将可以正常工作。

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是访问数据库文件),是我想使它也可以在C驱动器中工作。

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

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. 您是老学校...这些天C禁区。

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. Program Data文件夹用于应用程序特定的数据-或对于用户数据,使用%AppData%文件夹在其中创建应用程序的文件夹,并将此文件夹用于用户的数据。

Your problem is your database file is in %ProgramFiles%. 您的问题是数据库文件位于%ProgramFiles%中。 It should be in %AppData% 它应该在%AppData%中

There are two ways to resolve 有两种解决方法

1.modify the setup project. 1.修改安装项目。 when you make the setup,you should specify the path of f.mdf,ensure that the file will install into AppData folder. 进行设置时,应指定f.mdf的路径,确保该文件将安装到AppData文件夹中。

2.copy f.mdf to AppData folder by app. 2.按应用将f.mdf复制到AppData文件夹。 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: 每次运行应用程序时,第一件事就是将文件复制到AppData文件夹,您可以在Main(或init)方法中添加以下代码,然后重试:

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. * 1更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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