无法打开数据库“数据库”由登录请求

发布于 2024-09-28 22:35:13 字数 5549 浏览 0 评论 0原文

我正在开发一个示例 .Net MVC 应用程序。我已将 aspnet 成员资格 api 表添加到现有数据库中。我对 web.config 文件进行了如下修改:

<connectionStrings>
    <add name="ApplicationServices" connectionString="Data Source=localhost;Initial Catalog=nerddinner;Integrated Security=True;User Instance=true" providerName="System.Data.SqlClient" />
    <add name="nerddinnerEntities" connectionString="metadata=res://*/Models.NerdDinner.csdl|res://*/Models.NerdDinner.ssdl|res://*/Models.NerdDinner.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=localhost;Initial Catalog=nerddinner;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

在我的实际应用程序中,如果我想注册为用户,单击提交时会出现以下异常:

$exception  {"Cannot open database \"nerddinner\" requested by the login. The login failed.\r\nLogin failed for user 'TaraW-PC\\TaraW'."}   System.Exception {System.Data.SqlClient.SqlException}

我正在使用 Visual Studio 2010 和 SQL Server 2008。我安装了 SQL Server 我安装了带有 Windows 身份验证的默认实例。

我没有更改在 MVC 应用程序中自动创建的 AccountModel.cs,但是这本书暗示我不必这样做才能注册新用户。

我希望我知道堆栈跟踪的含义,但对于任何知道的人来说,这里是:

[SqlException (0x80131904): Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2030802
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009584
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +215
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +987
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
   System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +178
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
   System.Web.Util.SecUtility.CheckSchemaVersion(ProviderBase provider, SqlConnection connection, String[] features, String version, Int32& schemaVersionCheck) +392
   System.Web.Security.SqlMembershipProvider.CheckSchemaVersion(SqlConnection connection) +84
   System.Web.Security.SqlMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) +2517
   NerdDinner.Models.AccountMembershipService.CreateUser(String userName, String password, String email) in C:\Users\TaraW\Documents\Visual Studio 2010\Projects\MVC\NerdDinner\NerdDinner\Models\AccountModels.cs:127
   NerdDinner.Controllers.AccountController.Register(RegisterModel model) in C:\Users\TaraW\Documents\Visual Studio 2010\Projects\MVC\NerdDinner\NerdDinner\Controllers\AccountController.cs:93
   lambda_method(Closure , ControllerBase , Object[] ) +162
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +51
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +409
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +52
   System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +127
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
   System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +305
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830
   System.Web.Mvc.Controller.ExecuteCore() +136
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +111
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +65
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +42
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +52
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8841105
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184 

I'm working through a sample .Net MVC application. I've added the aspnet membership api tables to an existing database. I've modified the web.config file as follows:

<connectionStrings>
    <add name="ApplicationServices" connectionString="Data Source=localhost;Initial Catalog=nerddinner;Integrated Security=True;User Instance=true" providerName="System.Data.SqlClient" />
    <add name="nerddinnerEntities" connectionString="metadata=res://*/Models.NerdDinner.csdl|res://*/Models.NerdDinner.ssdl|res://*/Models.NerdDinner.msl;provider=System.Data.SqlClient;provider connection string="Data Source=localhost;Initial Catalog=nerddinner;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
  </connectionStrings>

In my actual application then, if I want to register as a user, I get the following exception on clicking submit:

$exception  {"Cannot open database \"nerddinner\" requested by the login. The login failed.\r\nLogin failed for user 'TaraW-PC\\TaraW'."}   System.Exception {System.Data.SqlClient.SqlException}

I'm using Visual Studio 2010, and SQL Server 2008. When I installed SQL Server I installed the default instance with windows authentication.

I haven't changed the AccountModel.cs that was automatically created in the MVC application, however the book implies I should not have to in order to register a new user.

I wish I knew what the stack trace meant, but for anyone know does, here it is:

[SqlException (0x80131904): Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2030802
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009584
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +215
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +987
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
   System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +178
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
   System.Web.Util.SecUtility.CheckSchemaVersion(ProviderBase provider, SqlConnection connection, String[] features, String version, Int32& schemaVersionCheck) +392
   System.Web.Security.SqlMembershipProvider.CheckSchemaVersion(SqlConnection connection) +84
   System.Web.Security.SqlMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) +2517
   NerdDinner.Models.AccountMembershipService.CreateUser(String userName, String password, String email) in C:\Users\TaraW\Documents\Visual Studio 2010\Projects\MVC\NerdDinner\NerdDinner\Models\AccountModels.cs:127
   NerdDinner.Controllers.AccountController.Register(RegisterModel model) in C:\Users\TaraW\Documents\Visual Studio 2010\Projects\MVC\NerdDinner\NerdDinner\Controllers\AccountController.cs:93
   lambda_method(Closure , ControllerBase , Object[] ) +162
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +51
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +409
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +52
   System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +127
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
   System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +305
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830
   System.Web.Mvc.Controller.ExecuteCore() +136
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +111
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +65
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +42
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +52
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8841105
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沧桑㈠ 2024-10-05 22:35:13

正如正确所述,@no_one 和 @Darkxes 问题应该出现在集成安全检查中。

尝试执行:

exec sp_grantlogin 'TaraW-PC\TaraW' 
go 

use nerddinner 
go 

exec sp_grantdbaccess 'TaraW-PC\TaraW' 
go

As correctly stated @no_one and @Darkxes problem should be in Integrated security check.

Try exec:

exec sp_grantlogin 'TaraW-PC\TaraW' 
go 

use nerddinner 
go 

exec sp_grantdbaccess 'TaraW-PC\TaraW' 
go
怼怹恏 2024-10-05 22:35:13

我认为您需要模拟应用程序,也许您正在尝试与刚刚注册的用户连接,并且应该是您模拟的 asp.net 用户连接数据库,而不是刚刚在会员提供程序上创建的用户...

I think you need to impersonate the app cause, maybe you are trying to connect with the just registered user, and it should be you asp.net user impersonated who connects the DB, not the user just created on the Membership provider ...

月下客 2024-10-05 22:35:13

由于您在集成安全性下运行,请检查以下内容。

检查用户是否有权限登录服务器。

  1. 如果您使用的是 Visual Studio Web
    服务器,如果是哪个帐号
    您正在运行的权限
    SQL Server 和数据库。

  2. 如果您在 IIS 下运行,如果
    其下的应用程序池
    你的应用程序正在运行
    数据库服务器上的权限
    和数据库。

Since you are running under Integrated security check the following.

Check if the user has permissions to login to the server.

  1. If you are using Visual Studio Web
    Server, if the account under which
    you are running has permissions to
    SQL Server and the database.

  2. If you are running under IIS , if
    the application pool under which
    your application is running has
    permissions on the database server
    and database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文