Unable to update database .MDF is Read Only
The MDF file would be readonly either because the readonly file attribute flag is set, in which case you have to unset it, or another program has the MDF file locked as readonly. Are you running a version of SQL server that is using that file?
I've never seen a connection to the MDF file directly, usually it's done via the server, and the server will manage all the IO for the MDF file.
E.g. a typical connection string for SQL Server:
Database=<dbname>;Server=<servername>;MultipleActiveResultSets=True;Connection Timeout=10;User Id=<username>;Password=<password>;
Additional links:
1) Failed to update .mdf database because the database is read-only (Windows application)
2) Failed to update database because it is read-only
3) Failed to update database "*.mdf" because read only EntityFramework
4) http://www.codeproject.com/Questions/183758/Failed-to-update-mdf-database-because-the-database
Failed to update .mdf database because the database is read-only (Windows application)
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
Failed to update database *.mdf because read only EntityFramework
I keep my DB near .exe file, in folder "DAL/AppData".
Yes. Can it be you mean that this is in the programs file folder, you know.
THe one that windows specs of the last 10 years say is "read only" for normal users?
OUCH.
THer are folders for storing data. There is a SpecialFolders enumeration to get the valid path of every such folder.
How can I allow write access on other machines? Can I do it programmatically?
On a SQL Server, this is done by allowing the other computer to access the server, not the data files. I.e. you connect to the SQL Server on the other machine, which is having the database loaded.
I've read that I can place DB into AppRoaming Folder, but this is not my variant.
First, that would be stupid unless you do actually plan for roaming - SQL shold go into a local folder, never roaming.
Second, "not my variant" is like "Hey, I drive the car against the rules, what can I do not to get speeding tickets". And "following the law is not my variant". Your variant is something WIndows does not care for. Learn how to install your software according to the windows guideline which is VERY clear where changing data should NOT be.
Failed to update database because the database is read only
I would check the file system privileges. I suppose you talk about an SQL server file database. You receive the message because the account trying to access your file database does not have the file system permissions to do so.
In order to confirm my suggestion, you allow everyone to access the specific directory with full permissions.
Then, you have to check what is the account trying to do the actual access. Probably it's a system account (user ASPNET or NETWORK SERVICE). You have to give the respective permissions to the specific account.
Then, restart IIS.
If you want to do this for a distributed stand-alone application. Then these permissions would have to change on each machine where the program would be installed. In order to avoid putting users in such a fuss, the setup program should do it. I am not an expert on setup programs, but even the simplest ones would give you the option to do it, after asking the system adminstrator's approval. I suppose you could build a custom action during the setup program which would change the specific folder's permissions, perhaps by using xcacls.exe.
Hope I helped!
C# Application deployment: Failed to update database because the database is read only
Okay I dont know why I didn't got any answers yet. Was really trying to fix this issue and finally found the solution.
On your Database global configuration file that you have created within your project to manage all your database related work like add, delete, update and connection. For a local database define a LocalDbPath like this:
public string LocalDBPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Then use the same LocalDBPath
everywhere in your database connection.
While deploying the project via Setup and Deployment go to:
File System Editor
- Right Click on
File System on Target Machine
- Select
Add Special Folder
- Select
User's Application Data Folder
- And Add your Database file by going into
User's Application Data Folder
-> Right ClickAdd
->File
and choose the file.
Build your solution and you are good to go. Cheers!
Failed to update database because it is read-only
thanks for the help. I just found a solution. in the App_Data ACL, I had two entries : Network Service and IIS_IUSRS. the Network Service account had full permissions but IIS_IUSRS group had only read access. so, I gave IIS_IUSRS full permissions as well and it worked !
thanks again.
Related Topics
Alternative to Findmimefromdata Method in Urlmon.Dll One Which Has More Mime Types
How to Insert Characters to a File Using C#
Monitor Process Start in the System
Performing a Mouse Click Without Moving Cursor
The Operation Cannot Be Completed Because the Dbcontext Has Been Disposed Error
Using Graphics.Drawimage() to Draw Image with Transparency/Alpha Channel
Multicast Delegate of Type Func (With Return Value)
C#: Cast to Generic Interface with Base Type
Using Libtiff from C# (To Access Tiled Tiff Images)
How to Get a Unique Identifier for a Device Within Windows 10 Universal
Cookie Authentication Expiring Too Soon in ASP.NET Core
Remove Item in Dictionary Based on Value
The Type Initializer for 'Emgu.Cv.Cvinvoke' Threw an Exception
Get List<> Element Position in C# Using Linq