views:

32

answers:

2

Hi guys,

I'm running the nerddinner MVC application on visual studio, and the database is on sql server 2008. I was previously having problems with permissions, etc but I seemed to have these sorted.

I created a user - taraw in SQL Server Management Studio, and got this all working. I can log into it fine.

When I test the application, I can see all the database entries, it is only however when I want to register a new user that the application crashes with this error: closed.

Failed to generate a user instance of SQL Server. Only an integrated connection can generate a user instance. The connection will be closed.

I am using the aspnet membership api to register and maintain user accounts. I used the aspnet_regsql.exe tool to add the api tables to my existing database.

This is the connection string I have in the web.config file:

<connectionStrings>
    <add name="ApplicationServices" connectionString="Data Source=localhost;Initial Catalog=nerddinner;user id=taraw;password=Password;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;user id=taraw;password=Password;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

I would imagine the problem is with the Application Services connection string as I can see all the other information from the database fine.

Here is the stack trace,

    [SqlException (0x80131904): Failed to generate a user instance of SQL Server. Only an integrated connection can generate a user instance. The connection will be closed.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009598
   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.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +5023255
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
   System.Data.SqlClient.SqlConnection.Open() +125
   System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +95
   System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +206
   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

EDIT:

I have also tried the following commands:

1>EXEC sp_grantlogin 'TaraW-PC\TaraW'  
 2>GO

 1>USE nerddinner
 2>GO

 1>EXEC sp_grantdbaccess 'TaraW-PC\TaraW'  
 2>GO

 1>EXIT

however I get the following error for that:

Msg 15063, Level 16, State 1, Server TARAW-PC, Line 1 The login already has an account under a different user nameclosed.

A: 

Removed "User Instance = true" from Application Services connection string. Did the trick for me.

TaraWalsh
+1  A: 

Best bet would be to leave user instance on and to let it use integrated security, then ASP.NET can create/own the database and you won't have to worry about it.

Anyhow, granting access to the windows account 'TaraW-PC\TaraW' won't help a lick here as you are not logging in with that account, you are logging in with a sql account called taraw. What you need to do is:

1) run aspnet_regsql to create your application services database.
2) create said account in the database
3) add that account to the various aspnetdb roles you'd need.

Wyatt Barnett