I have created a windows application with access on its backend. the problem is that when I installed it it shows operation must use updateable query when i try to insert or update operation ....After this I changed permission of folder where access database resides.Now it works fine.Now the problems is that on each computer where i install it I need to change write permissions on database folder in program files . Is there any solution for this where I can set permissions for my folder at setup creation time. or any other solution u know.....thanks in advance
Don't put your database in your program folder.
In the newest operating system like Win7 or Vista this folder is read-only for security reason.
The best place is the folder identified by the enum SpecialFolder.ApplicationData.
You get the physical path with:
string commonAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
Inside this path you should have a dedicated path for your application.
string myDataPath = Path.Combine(commonAppData, "MyApplicationDataFolder");
This scenario is good only if the application is not used by more than the user who installed the software. If you require a multiuser access to your database then you create by yourself a folder on the local disk or in a network share where each user can reach the database.
Usually the work of placing the database backend on the user machine or in a network share is reserved to the installation tool. Numerous tools exist on the market, free and paid. I don't know which tool you use and I can't suggest one or another. However when you select/use one you should check for the presence of these base functionality:
Ability to refer to the special folders present in the Windows
Environment. (MyDocuments, ApplicationData, etc...)
Ability to create sub-folders in these special folders (MyApplicationData)
Ability to create network shares or use one already present
Ability to update your configuration file where you store your
connection string (string replacing)
If the deployment tool works as expected you don't need to do anything inside your application, you read the connectionstring from your config file and open the database.
Create a text file with exactly same content below and save the file having extension '.reg'.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Access\Security\Trusted Locations\Location2]
"Path"="C:\\Program Files\\Microsoft Office\\Office12\\ACCWIZ1\\"
"Description"="Access default location: Wizard Databases"
Test this registry file with double clicking onthis. it will create anew entry in registry.
Save the reg file with your installer and run it with installer. You can execute this file from c# code also.
registry_hacks_reg
Related
I've created a database windows application using in C#. My application is running successfully on Windows XP, but it doesn't properly execute on Vista or Windows 7 systems. My application shows a message similar to
Failed to update .mdf database because the database is read-only
Can anyone give me a solution to this?
The big thing that changed between Windows XP and Windows Vista/7 is the introduction of UAC which means that users, even if created as administrators, don't routinely have read/write access to "important" locations such as the %programfiles% (Usually C:\Program Files or C:\Program Files (x86)) directory. This is why your application works on Windows XP and not on Windows Vista.
You need to store your DATA in the %programdata% directory (which is usually C:\ProgramData) if the data is shared between users on the machine or %appdata% (which is usually C:\Users\USERNAME_GOES_HERE\AppData\Roaming) if it is specific to a given user. You'll now no longer encounter the problem of being unable to write to the file.
The reason for this is that by storing data in your programs installation directory you were doing the wrong thing. Windows didn't stop you from doing this previously, but it was fairly widely documented that %programfiles% was not the appropriate place to store data.
If the MDB file is in your application path, then the default permissions would require elevation of rights to be able to write to the files -- I'd recommend moving the data to the ApplicationData shared folder, where end users will have write permissions by default
I ran into this related to localdb, the file is named:
myfolder/mysolution/myproject/App_Data/something.mdf
The way I fixed it is to right-click on the top level folder (myfolder) and then choose Properties, then choose Edit, then select Users, add to users either the Modify permission or both Modify and full control (this is a development environment) and then click apply.
So in other words, in my experience, it doesn't matter what folder you put the localdb in, you just need to give Users permission to write.
You should add the Modify permissions for IIS_IUSRS user to *.mdf file.
go to the folder Where the program is installed and right click on the database file and Properties -> Security -> Group or Username (Click users one by one and see below for the permissions)
If for the user if not set to full control, then click EDIT -> Select the user and give full control..
we have a suite of applications which are add-ons to an enterprise product installed onto a windows server into the program files(x86) folder. The applications are written in c#. A share is created on the server allowing users to launch the applications in the installation folder either by terminal server or across the network.
The common settings for our applications are stored within a single xml file. Some of these settings only need to be read and are configured by a dedicated application that requires admin rights (as it also performs other functions such as scheduling tasks). Other settings need to be modified by various department managers to suit they way they want the applications to work and should not require admin access - but they need to be persisted in the same file as they are application rather than user specific.
I am somewhat confused with all of the available options for where the settings file might be stored (including special folders) such that admin access is not required to write to the file, yet the file location is accessible irrespective of whether the user is launching the application via terminal server, network share etc.
Is the program files folder the best option and just creating the necessary permissions on the share? Or is there a special folder for this scenario? If there is a special folder, what is the correct way to access it? (I did try this route, but kept finding the file was being created/updated on the user's local machine rather than the network file).
thanks
Matt
My program contains a sql lite db file which my program creates after first run and then stores the data inside updon app usage. The database builds up over a period of time.
The db file is created in the installation directory of the program
I have to update the app on a regular basis when there are bugs fixed, so basically I publish a new msi installer, the installer removes old installation files except db file and install new program files.
Some user's do not install it to the default location so in their selected location the db file is not present.
I want to know if it's ok to store data files to some program data folder outside the install dir ? so that every new update of my program can access the data from that program data folder.. ?
Is there any program data directory in windows xp, vista and 7 ? and how to access it in C#/
Have a look Environment.SpecialFolder Enum to decide about the right place for your data.
I would vote for Recent folder though, here are other options:
ApplicationData (Current users roaming profile)
CommonApplicationData (All users on local machine)
LocalApplicationData (Current user on local machine)
Get the folder of your choice with
Environment.GetFolderPath(Environment.SpecialFolder.xxx))
It is very dangerous to store user data in the application folder. Not only will the data be destroyed if the user updates or uninstalls your app, but Standard users cannot even write to the app directory.
I typically include a seed database in the application and copy it to a folder in the Environment.SpecialFolder.ApplicationData folder when the application launches. All user data is stored in the copy; if the user uninstalls the application the seed database is deleted but the user data remains. See this SO answer for an example.
You should not store data in the install folder. Try this. The special folders are designed for you to be able to store this kind of data. There is also the Application Settings, which are asy to access and provide an easy way to store user key value pair, Information.
I have an Sql Compact Database v3.5 that I'm bundling with my application. When the application is installed, the database is copied into the application's Program Files directory.
Because of Vista and Win7's security settings, the installed application can't access the database file. It is merely a problem of having the database file reside in the Program Files.
The solution I have thought of is to copy the file into Program Data, but does anyone have another solution? I am sure others have come across a similar problem.
Thanks in advance for your input.
store the application data in the user's application data directory. Or in 'default user'. The user has permission to this directory and that is the intended purpose.
http://blog.kowalczyk.info/article/Getting-user-specific-application-data-directory.html
Use the Environment.SpecialFolder property. Place the DB file either in the app data all users or app data of the specific user.
Probably will need some setting at install like most applications these days.
In my C# application, if I wanted to be able to download an "add-in" from our website and store it locally on the user's computer, and then run it (assume it's an assembly DLL or EXE, doesn't matter), I assume I can't store it in a subdirectory of my Program Files folder, and that's not really the right place for it since add-ins are user-specific. Where should I store these, and what kinds of trust/security issues might I run into?
The application data directory of the current user would be one place to store them.
string basePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
basePath = System.IO.Path.Combine(basePath, "MyProgram");
if (!Directory.Exists(basePath))
Directory.CreateDirectory(basePath);
Trying to write anything inside of Program files after installation will run into problems in Vista, Windows 2008 server, Windows 7 and later. Unless of course your application requires elevation. Also you mentioned your files are specific per user.
Use the IsolatedStorage class provided in .NET for storing user specific stuff.
More information: Working with Isolated Storage in .NET