C#应用程序无法更新Access数据库部署后到" C:\Program Files\ ..." [英] C# application cannot update Access database after deployment to "C:\Program Files\..."

查看:296
本文介绍了C#应用程序无法更新Access数据库部署后到" C:\Program Files\ ..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经部署了我的应用做好准备,以供其他用户(另一台计算机),但是当我尝试将数据添加到数据库中,我得到的错误

I have deployed my application to be ready for use by another user (another computer), but when I try to add the data to the database I get the error

操作必须使用一个可更新的查询

Operation must use an updatable query

该错误是这样的(这是当我已经部署了我程序和应用程序下运行,而不是在Visual Studio中):

The error is like this (This is when I already deployed my program and run under application, not under Visual Studio):

但它在Visual Studio中完美的作品,这样的形象(注意,图像上的错误上面出现一次我点击提交按钮时,它应该存储在数据库中,并在datagridview的如下像图像)显示它

But it works perfectly under visual studio, the image like this (note that, the error on the image above appear once I click the submit button, it supposed to stored in the database, and display it on the datagridview as like image below):

和还我得到了另一个问题,删除功能没有运行,在错误添加和删​​除出现一次我部署了我的计划,但我会张贴在另一个线程。

And also I got another problem, the delete function is not running, the error on the add and delete appear once I deployed my program, but I will post that on another thread.

我要如何解决这个问题?

How do I solve this?

推荐答案

在一个Visual Studio应用程序正在开发它驻留在一个文件夹中到显影剂具有读/写访问。这显然​​是必要的,因为开发者需要能够编辑源代码文件。如果将与代码的数据库文件,然后,因为它是在一个可写位置,应用程序可以更新数据库文件

When a Visual Studio application is under development it resides in a folder to which the developer has read/write access. This is obviously necessary since the developer needs to be able to edit the source code files. If you place a database file "in with the code" then the application can update the database file because it is in a "writable" location.

然而,如果在部署数据库文件保持与代码,并安装程序会将文件(如可执行文件和数据库文件)到的%ProgramFiles%在目标机器上(例如, C:\Program Files\MyApplication ),那么普通用户将不会有那个位置的写入权限。在的%ProgramFiles%一般限于文件为只读,以防止恶意软件的系统。

However, if on deployment the database file stays "with the code" and the installer puts the files (i.e., the executable file and the database file) into %ProgramFiles% on the target machine (for example, C:\Program Files\MyApplication) then the average user will not have write access to that location. Files in %ProgramFiles% are normally restricted to read-only to protect the system from malware.

有人会尝试并配置安装在的%ProgramFiles%授予普通用户写访问某些文件(S)或文件夹(S),但是这是一个坏主意和贸易; 。安装程序应该将数据库文件确实复制到通常读预期的用户(S)/写入的位置:要么%USERPROFILE%(特定用户),或%的公众%(针对所有用户)。

Some people will try and configure the installer to grant write access to normal users for some file(s) or folder(s) under %ProgramFiles% but that is a Bad Idea™. The installer should really copy the database file to a location that is normally read/write for the intended user(s): either %USERPROFILE% (for a specific user), or %PUBLIC% (for all users).

这篇关于C#应用程序无法更新Access数据库部署后到" C:\Program Files\ ..."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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