localdb readonly database problems

2019-06-10 06:36发布

问题:

enviroment

visualStudio 2012 localdb v11

a solution with 3 projects on it:

1st class library with an ORM database model, and a local db Localdb.mdf inside App_Data directory.

2nd is a web project that uses this database model.

and 3rd a c# console project that uses this localdb database, referencing the 1st class library, and having at the app.config a localdb connection string defined as:

Data Source=(LocalDB)\v11.0;AttachDbFilename=C:_work_desarrollo\Apps\Business\OpenAccessAppsModel\App_Data\LocalDb.mdf;Integrated Security=True

My problems are: i would like to made some changes using VS 2012 server explorer to this database like deleting tables and i got "The database is readonly. Updates to the database will not succeed until the database is made read write"

and second, how can i made available to the console application (the 3rd project) the database file so i can copy/paste the release folder to "install" the console application? How the database connection should be modified to have the database locally with the console applciation? (same directory as the app)

Thanks a lot

回答1:

Happened to me today.

You can grant/change db permissions like this:

icacls mydabase*.* /grant "NT Service\MSSQL$SQLEXPRESS":(F)

icacls mydabase*.* /grant "MYMACHINENAME\Administrator":(F)

I already had sqlexpress permissions set but found out that machine\administrator was also needed.

Hope it helps.



回答2:

Please check atribute of .mdf and .ldf files and the container folder.

Check this answer as well. I've done these two things and Presto! It Works!



回答3:

The problem is only file .mdf and .log permissions over the user or application execution. Only give the security permission read and write in the file properties and the connection string for example "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\WinApps17\Cash\Invoices\Data\VFindx.mdf;Integrated Security=True;Connect Timeout=30"



标签: localdb