2

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

Siocki
  • 53
  • 2
  • 9

2 Answers2

1

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.

Community
  • 1
  • 1
Dan H
  • 1,828
  • 2
  • 21
  • 38
  • I think this is not the case. The database that is accessed is generated in locadDB folder, and I cannot simply move it (or can I?). The problem is that I was ordered to make the implementation of the application that was written by someone else, and I don't know the whole code. – Siocki Jun 20 '14 at 13:22
  • I updated my answer with another approach, maybe that will get it done. – Dan H Jun 20 '14 at 13:29
  • I am quiet newbie in this topic, co could you tell me how to do it? I found only the description of Network Service as the account. – Siocki Jun 20 '14 at 13:43
  • First find the .mdf and .idf files. One at a time, right click on it and select Properties > Security tab. Click the Edit button, then the Add button. Then click Advanced button. There you need to make sure "From this location:" is set to the machine and not a domain. You can click the Locations button and select to top machine to make sure. Once that's done click the Find Now button. Select NETWORK SERVICE and IIS_IUSRS, then click Ok and Ok again. They will now appear in the list and you can select them and check modify and write in the permissions box. Then click Ok and try it. – Dan H Jun 20 '14 at 13:45
  • And one more thing, when the database is created, it doesn't display in the folder. I think it's crucial – Siocki Jun 20 '14 at 13:48
  • After you update the permissions restart IIS. Where are the .mdf and .idf files located? – Dan H Jun 20 '14 at 13:55
  • Again, the same problem. Nothing has changed. The are located in instance in LocalDB folder – Siocki Jun 20 '14 at 13:58
  • Ok it works, I changed persmission for the whole application and it worked – Siocki Jun 20 '14 at 14:03
0

I Changed the permissions of the entire folder where the website was hosted. I added all permissions for Users to be broad and it worked. Try this first to be sure and then narrow it down to specific users.

A restart of the IIS was not required.

msysmilu
  • 2,015
  • 23
  • 24