Ms access and vb.net [duplicate] - c#

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

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

Related

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

Unauthorized Access Exception writing file from .exe

My WPF application writes an XML file to a folder within the CommonApplicationData folder on a Windows 7/64 machine. This works fine from Visual Studio 2010. When running from the .EXE file, I get a System.UnauthorizedAccessException when writing the file.
Is this a problem with my initial setup of the folder? Or is this related to the permissions of the executable file itself? Not quite sure how to handle this one??
Paul
I think that it is a problem with permissions to the folder.
Probably Visual Studio runs your application as an administrator and the .EXE file is executed as a normal user.
Perhaps you want to re-evaluate storing that data (XML) in that location all the time. Limited users won't be able to write to it. Sure, you can force admin privs but your users may not always have that option (and it's kinda a hack anyway).
The question below seems to outline a work-around depending on the user's priv level.
writing files to Common Application Data folder denied
Right click on the *.exe file and "Run as administrator".

SQLite database file location and environment

I have developed a little software for Windows few weeks now and got problems when trying to make proper installer for it.
I got spesific request that database file has to be in same folder where program is so user can take own backups every now and then.
When I install it (using Visual Studio 2012 and InstallShield Limited Edition project) it works in my main computer(W7 64-bit), my laptop(W8 64-bit) and my buddys Laptop(W8 32-bit) just fine.
My main computer runs program as it should, it uses database file from programs Database -folder(C:/Program Files (x86)/Program Name/Program Name/Database) and doesnt create additional db files but my laptop and my friends laptop create folder to
"C:/Users/User/AppData/Local/VirtualStore/Program Files (x86)/Program Name/Program
Name/Database" and use database from there.
Also I noticed that program crash on start on my other test computer that runs W7 32-bit and I made sure that .Net Framework was installed.
Connection string goes like: sqLiteConnection1.ConnectionString = "data source=.\\Database\\db";
Program's Platform target is set to Any CPU and it uses .Net Framework 4.5 if that helps anything.
Any ideas whats causing this and how I can fix it?
database file has to be in same folder where program is so user can take own backups
Danger Will Robinson! Non-admin users cannot modify files in the shared or Program Files folder. You are forcing users to run as Admins, or change the Program Files folder so non-Admins can modify it; both are serious security vulnerabilities.
If you install the database to the Programs folder, then the database is part of the install and not user data. This means that repairing or uninstalling the application will delete all user data. Users don't like that.
Your application should copy the application database to a user folder like Environment.SpecialFolder.ApplicationData and save all changes there. All users can modify and backup data from their own folders, no security vulnerabilities required. Also, when someone repairs or uninstalls the application, all users get to keep their data.
Your connection string is using current directory (.).
Create it dynamically with Assembly.GetExecutingAssembly().Location.

.NET including class library database (and other resources) with windows app deployment

I have a class library that attaches itself a tiny SQL Server database that resides in its Data Directory. When i'm using this class library with another windows application i see that once i compile my code, the database files get copied to the bin folder of my windows app project. However when i publish the windows app,install, and run it, i get the error 'An attempt to attach an auto-named database for file C:\Documents and Settings\User\Local Settings\Apps\2.0\Data..\DB.mdf failed.' Obviously this folder doesn't have the mdf files.
I guess this won't be a problem if i just add the database files to my windows application project. But surely there's a better way?
You could include an SQL script for creating the database into your "installation/run first time routine".
I guess that you've already stated that having a form of SQL Server is an installtion prerequisite.
For the data files I would recommend that you use a variable connection string for accessing your database. That way you can change the installation routine to include asking the user where they wish to have the data files installed and save that as part of your connection string to the app.config file.
Conversely you could also use the users selection of where to install the app to override the relative path stored for the database within your code (using the same connection string variable as mentioned above).

Create a Setup File Windows.Net C#

I have created a windows application setup program, it needs to have a text file in the application folder. The file is also included while creating the setup.
Once the setup successfully completes and my program tries to modify the file based on user input, its simple throwing an exception.
I am using Windows 7 Home Premium OS.
Any suggestion/help will be great to overcome this issue.
This is normal on a Vista or Win7 machine. Or a properly secured XP machine for that matter. The normal install location for programs, like c:\program files\your company\your app, is read only for most users. UAC is a counter-measure to malware messing with programs.
You'll need to store the text file into a writable location, the AppData folder. In the Setup project, right-click "File system on target machine" and select User's Application Data Folder. Find that file back at runtime through Environment.GetFolderPath, passing Environment.SpecialFolder.ApplicationData. Or use "User's Personal Data Folder" if the user should be able to find it back easily through the Documents folder.
What exception is being thrown? It could be a UAC issue.

Categories