问题描述
我开发了一个运输票务系统,使用Visual C#2008 Express作为前端,Microsoft Access 2010作为后端。
该应用程序在存储当前Access数据库上的所有数据的开发PC上工作正常并最终打印收到但我的问题是如何在数据库正常工作的另一台计算机上成功运行此应用程序在开发PC上。
在运行应用程序后将应用程序发布并部署到另一台计算机后,它会抛出一个错误,指示无法找到数据库路径。 />
我在解决这个问题时需要认真的帮助。
我尝试了什么:
connection.ConnectionString = @ Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\ Users \ MY CLASS \Downloads \ good work \ new work \ MDIFORM\busdata.accdb;
Persist Security Info = False;;
您需要确保将数据库复制到相应的文件夹中。
如果您已将数据库包含在Visual Studio项目中(即它在解决方案资源管理器中可见)然后您可以单击该文件,转到属性窗口并将复制到输出目录
的设置更改为始终复制。
这样数据库将作为项目的一部分进行部署。
或者将文件复制为部署脚本中的一个步骤 - 您可能需要在目标PC上创建该文件夹。为了使这更容易,你的连接字符串移动到App.Config文件(并确保复制始终
)
或者,将数据库存储在目标PC所连接的网络驱动器上(不建议使用Access)
请参阅: [] - 它建议一些更好的地方来保存它,并显示如何访问它们!
您的问题是您将数据库路径硬编码到开发PC的本地磁盘。
数据库必须在服务器上。
I have developed a transport ticketing system using Visual C#2008 Express as front end and Microsoft Access 2010 as back end.
The application works fine on the development PC storing all data currently on the Access database and prints a reciept eventually but my problem is how to run this application successfully on another computer with the database functioning normally as it works on the development PC.
After publishing and deploying the application to another computer upon running the application, it throws an error indicating that the database path cannot be found.
I need serious help as regard resolving this issue.
What I have tried:
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\MY CLASS\Downloads\good work\new work\MDIFORM\busdata.accdb; Persist Security Info=False;";
If you have included the database in your Visual Studio project (i.e. it is visible in Solution Explorer) then you can click on the file, go to the Properties window and change the setting for
Copy to Output Directory
to "Copy Always". That way the database will be deployed as part of your project.
Alternatively copy the file as a step in your deployment script - you may need to create the folder on the target PC. To make this easier move your connection string to the App.Config file (and make sure that is
Copy Always
too)Alternatively, store the database on a network drive that the target PC is connected to (not recommended with Access however)
See here: Where should I store my data?[^] - it suggests some much better places to keep it, and shows how to access them!
Your problem is that you hard coded the database path to local disk of development PC.
Database must be on server.
这篇关于如何在没有数据库路径错误的开发计算机以外的其他计算机上安装和运行带有访问数据库的C#应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!