title: Cannot open database, Login failed for user
body: <p>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.</p>
  
  <p>I created a user - taraw in SQL Server Management Studio, and got this all working. I can log into it fine. </p>
  
  <p>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.</p>
  
  <blockquote>
    <p>Failed to generate a user instance of
    SQL Server. Only an integrated
    connection can generate a user
    instance. The connection will be
    closed.</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>This is the connection string I have in the web.config file:</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="ApplicationServices" connectionString="Data Source=localhost;Initial Catalog=nerddinner;user id=taraw;password=Password;User Instance=true" providerName="System.Data.SqlClient" /&gt;
      &lt;add name="nerddinnerEntities" connectionString="metadata=res://*/Models.NerdDinner.csdl|res://*/Models.NerdDinner.ssdl|res://*/Models.NerdDinner.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=localhost;Initial Catalog=nerddinner;user id=taraw;password=Password;MultipleActiveResultSets=True&amp;quot;" providerName="System.Data.EntityClient" /&gt;
    &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>I would imagine the problem is with the Application Services connection string as I can see all the other information from the database fine.</p>
  
  <p>Here is the stack trace,</p>
  
  <pre><code>    [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&amp; 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.&lt;&gt;c__DisplayClassd.&lt;InvokeActionMethodWithFilters&gt;b__a() +127
     System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
     System.Web.Mvc.&lt;&gt;c__DisplayClassf.&lt;InvokeActionMethodWithFilters&gt;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.&lt;&gt;c__DisplayClass8.&lt;BeginProcessRequest&gt;b__4() +65
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1.&lt;MakeVoidDelegate&gt;b__0() +44
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass8`1.&lt;BeginSynchronous&gt;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&amp; completedSynchronously) +184
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I have also tried the following commands:</p>
  
  <pre><code>1&gt;EXEC sp_grantlogin 'TaraW-PC\TaraW'  
   2&gt;GO
  
   1&gt;USE nerddinner
   2&gt;GO
  
   1&gt;EXEC sp_grantdbaccess 'TaraW-PC\TaraW'  
   2&gt;GO
  
   1&gt;EXIT
  </code></pre>
  
  <p>however I get the following error for that:</p>
  
  <blockquote>
    <p>Msg 15063, Level 16, State 1, Server
    TARAW-PC, Line 1 The login already has
    an account under a different user nameclosed.</p>
  </blockquote>