Search code examples
visual-studio-2010sql-server-2008setup-project

SQL Server 2008 Database Changing Read Only state to 'True' After Deployment


I'm creating a Installation Setup for one of my applications using visual studio setup project in VS2010. In which I'm accessing my database from application folder. I have added both MDF and LDF files to Data folder in Application folder. Everything works fine and I'm able to install the application, but when opening the application I'm getting an error saying 'Cannot update database because its read-only'. I have checked the database with SSMS and see that the Read-only flag is set to True by default and database is showing in gray color. After change the read only property the application works fine.I have done a lot of searching and rebuild-ed the project many times with changing the database. How can i get rid of this issue ?


Solution

  • A couple of possibilities:

    1. In your setup project, on the properties window of the DB file in the File System on Target Machine view, make sure you didn't accidentally set the Readonly property to true.

    2. If the database is in your Application folder in (for example) the Program Files folder, well that location is read-only to limited users. You haven't said whether your app is for all users or just administrators. If it's for a limited user then install the file to User's Personal folder or a location that limited users can write to. If the app requires admin privilege then your app needs an elevation manifest to cause it to run with admin privilege, if that's why the DB is readonly. Running your app as administrator would be a quick test to see if this is the issue.