如何在没有数据库路径错误的开发计算机以外的其他计算机上安装和运行带有访问数据库的C#应用​​程序 [英] How do I install and run my C# app with access database on another computer other than the development computer without database path error

查看:79
本文介绍了如何在没有数据库路径错误的开发计算机以外的其他计算机上安装和运行带有访问数据库的C#应用​​程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个运输票务系统,使用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;";

解决方案

You need to make sure that the database is copied into the appropriate folder.

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)


Unless your application installs the database to that specific location - which is both unlikely and not a good idea - it will fail to find the database file. If it tries, there is a very good chance that it won;t be allowed to find it as the User your app is being executed by is unlikely to automatically have permission to access the folder (unless his username happens to be "MY CLASS"
See here: Where should I store my data?[^] - it suggests some much better places to keep it, and shows how to access them!


Looks like you skipped the lesson on "networked apps and databases".

Your problem is that you hard coded the database path to local disk of development PC.
Database must be on server.


这篇关于如何在没有数据库路径错误的开发计算机以外的其他计算机上安装和运行带有访问数据库的C#应用​​程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆