我的应用程序在部署到“C:\Program Files\ ...”之后无法更新Access数据库。 [英] My application cannot update Access database after deployment to "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):
但它在视觉工作室下完美工作,这样的图像(请注意,上述图像上的错误出现,一旦我点击提交按钮,它应该存储在数据库中,并在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):
而且我还有另一个问题,删除功能没有运行,一旦我部署了我的程序,就会出现添加和删除,b
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.
我如何解决这个问题?
推荐答案
当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%下的某些文件或文件夹的普通用户的写访问权限,但这是一个坏主意和交易; 。安装程序应该真正将数据库文件复制到通常为预期用户读/写的位置:%USERPROFILE%
(对于特定用户)或%PUBLIC%
(适用于所有用户)。
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:\Program Files\ ...”之后无法更新Access数据库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!