我已经在代码优先方法(ASP.NET MVC)中编写了一个应用程序,现在我正在尝试在服务器上部署我的应用程序(Windows Server 2012)。当我在Visual Studio 2013 for WEB中测试它时,一切都很顺利。实施后,当我访问网站的网站时,我不能为例子添加下一个用户,因为:
无法更新数据库“MyDatabase”,因为数据库是只读的。
我检查了LocalDB文件夹中的实例,它们实际上是只读的。属性菜单中的更改不起作用。 这是堆栈树:
[SqlException(0x80131904):无法更新数据库“MyDatabase”,因为数据库是只读的。 System.Data.SqlClient.SqlConnection.OnError(SqlException异常,Boolean breakConnection,Action
1 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, TaskCompletionSource
1完成,Int32超时,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, IDictionary
2个参数)+258 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary`2参数)+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
答案 0 :(得分:0)
由于这是一个SQLExpress数据库,请看一下这个答案。它看起来与您遇到的问题相同。
Failed to update .mdf database because the database is read-only (Windows application)
<强>更新强>
对于.mdf和.idf文件,授予对NETWORK SERVICE用户,ASPNET用户和IIS_IUSRS组的写入和修改权限。
答案 1 :(得分:0)
我更改了托管网站的整个文件夹的权限。我已将Users
的所有权限添加为广泛且有效。首先尝试这一点,然后将其缩小到特定用户。
不需要重新启动IIS。