Search code examples
databaseasp.net-mvc-4webweb-deploymentlocaldb

Cannot update the database (LocalDB)


I have written an application in code-first approach (ASP.NET MVC), and now I am trying to deploy my application on a server (Windows Server 2012). When I test it in Visual Studio 2013 for WEB everything goes fine. After the implementation, when I access website for web, i cannot for example add next user because:

Failed to update database "MyDatabase" because the database is read-only.

I checked the instances in LocalDB folder, and they are really read-only. The change of it in properties menu doesn't work. This is stack tree:

[SqlException (0x80131904): Failed to update database "MyDatabase" because the database is read-only.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +388 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +815 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4515 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6553853 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +6556619 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +586 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +742 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +287 WebMatrix.Data.Database.Execute(String commandText, Object[] args) +178 WebMatrix.WebData.SimpleMembershipProvider.CheckPassword(IDatabase db, Int32 userId, String password) +455 WebMatrix.WebData.SimpleMembershipProvider.ValidateUser(String username, String password) +238 WebMatrix.WebData.WebSecurity.Login(String userName, String password, Boolean persistCookie) +73 MvcApplication4.Controllers.AccountController.Login(LoginModel model, String returnUrl) +132 lambda_method(Closure , ControllerBase , Object[] ) +179 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +258 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39 System.Web.Mvc.Async.<>c__DisplayClass42.b__41() +34 System.Web.Mvc.Async.<>c__DisplayClass39.b__33() +124 System.Web.Mvc.Async.<>c__DisplayClass4f.b__49() +786611 System.Web.Mvc.Async.<>c__DisplayClass4f.b__49() +786611 System.Web.Mvc.Async.<>c__DisplayClass37.b__36(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.<>c__DisplayClass2a.b__20() +33 System.Web.Mvc.Async.<>c__DisplayClass25.b__22(IAsyncResult asyncResult) +787092 System.Web.Mvc.<>c__DisplayClass1d.b__18(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51 System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288


Solution

  • Since this is a SQLExpress DB, take a look at this answer. It looks to be the same issue you are having.

    Failed to update .mdf database because the database is read-only (Windows application)

    Update

    For the .mdf and .idf files, give write and modify access to NETWORK SERVICE user, ASPNET user, and IIS_IUSRS group.