views:

87

answers:

3

Hey guys,

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=&quot;Data Source=localhost;Initial Catalog=nerddinner;Integrated Security=True;MultipleActiveResultSets=True&quot;" 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 
+1  A: 

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
Nick Martyshchenko
@Nick, Thanks for the reply. I did use the aspnet_regsql.exe tool. This is how I added the additional membership api tables (roles, membership, users, etc) to my existing nerddinner database.
TaraWalsh
But dbo.aspnet_CheckSchemaVersion is definetely created by this process. So maybe you register it for another database? Do you check manually via SQL Management Studio is there dbo.aspnet_CheckSchemaVersion stored procedure in nerddinner? You may check this via Server Explorer in VS too
Nick Martyshchenko
Hmmm, aspnet_SchemaVersions is there but not aspnet_CheckSchemaVersion. Is this perhaps a different name for it?
TaraWalsh
Take a look under Stored Procedures not Tables
Nick Martyshchenko
Sorry Nick! I've just checked under stored procedures and it's definitely there.
TaraWalsh
@TaraWalsh, I think no_one and Darkxes is right since you get "Cannot open database \"nerddinner\" requested by the login". You can do quick check by changing DB security mode to mixed security, add user or just enable sa and change your connection string to use user/login.
Nick Martyshchenko
Check this article for example How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0 http://bit.ly/b8A0S9 Do you install DB and do your development testing with same account?
Nick Martyshchenko
@Nick, I added a user (nerddinner) in SQL Server Management Studio with a password, However if I try to test this connection in Visual Studio It simply tells me "Login failed for user nerddinner" when I test the connection.
TaraWalsh
@TaraWalsh, Maybe you not change auth mode to mixed: How to: Change Server Authentication Mode http://bit.ly/bzpPme
Nick Martyshchenko
You can also try to fix your first Connection String: exec sp_grantlogin 'TaraW-PC\TaraW' go use nerddinnergoexec sp_grantdbaccess 'TaraW-PC\TaraW'go
Nick Martyshchenko
Hi Nick, It was disabled on the sa user, I created a new user because I couldn't remember the password for sa, and for the new user (nerddinner) I had this enabled, however it is still not allowing me to log in. It's so temper-mental!! :)
TaraWalsh
@Nick, I tried that using the command line prompt. I got the following message: "the login already has a different account under a different username."
TaraWalsh
Ok, let's try to end with one of our tries. So you created nerddinner, changed auth mode to mixed and tried to access to DB. Do you give your new user rights on DB, e.g. db owner? Also if you have fresh new SQL installation by default sa is disabled, you dont need to provide old password just enable it and change password to new.
Nick Martyshchenko
Hi Nick, sorry for the delay. I've been trying to log in to SQL Server Management studio using the nerddinner account but I get the following message: "Login failed for user 'nerddinner'. (Microsoft SQL Server, ERROR 18456)"...I've set everything correctly in the user account when I created it so this is driving me mad!!
TaraWalsh
On second thoughts Nick, this seems to have turned into a completely different question. You were right about the permissions but for some reason this doesn't seem to be working for me. I'll mark this as correct and start a new topic. Thanks for your help.
TaraWalsh
+1  A: 

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 ...

Darkxes
+1  A: 

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.

no_one
Hi @no_one, thanks for the reply. At the moment I am just running the application locally on my own laptop. Can you tell me how to check the permissions described in option 1?
TaraWalsh
see if you can connect to the database using SQL Server Management Studio. Use the TaraW-PC\\TaraW user.
no_one
Hi no_one, I can connect to the database fine using sql server management studio
TaraWalsh