I have a local DB that I have in an application. When I install it on another machine I get the error
Unable to update database.. .mdf is read only.<
.mdf
file in the folder and click PROPERTIES.OR
Just install your application in different folder other than ProgramFile(x86)
I solved the same problem as follows:
While creating "Setup", I manually added my database files database.mdf and database_log.ldf
into the Application Folder
file. But after adding these files, make sure that the ReadOnly
option in the Properties
section is False
.
Also "connectionString" I use:
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\database.mdf;Integrated Security=True;Connect Timeout=30"
First stop the SQLEXPRESS service from local-Services menu and then try to move and connect the database again by attaching database option in SQLEXPRESS. it should work. it works for me. :)
if your database file on the C volume, try to move the .mfd file to D volume
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