Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

c# - 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

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

enter image description here

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):

enter image description here

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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 FilesMyApplication) 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.

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...