I have been messing around with this for a few weeks, and I have finally decided to ask the question here. I have found similar issues on Stackoverflow, but nothing that is the same as my problem, and obviously, nothing that is close enough to help solve my issue.
I created a new MVC Web Project using Visual Studio 2015 CTP and used the template to create individual user accounts. When the project builds, I can debug the application, create a new user via the registration process, and then login as that user. OK so far!
So I went to Server Explorer and looked at the database. I replicated the database, tables and columns all on SQL Server 2005. I changed my connection string in the Web.config file to use the SQL Server Database instead of the local database.
I can connect to the database using Server Explorer, so the connection string is working fine, and everything is named exactly as the local db.
So I debug the application now and try and register a user, or login with the existing user that I copied over, and I get this error:
Server Error in '/' Application.
Invalid column name 'UserId'. Invalid column name 'UserId'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'UserId'. Invalid column name 'UserId'.
Source Error:
Line 76: // This doesn't count login failures towards account lockout Line 77: // To enable password failures to trigger account lockout, change to shouldLockout: true Line 78: var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); Line 79: switch (result) Line 80: {
The ID in the AspNetUsers is a column "ID" not UserId. It is the same in both the local and SQL Server 2005 databases, and when logging in with the local database, it works fine. I can REMark out the connection string and go back to the local db, and all is well again. I don't think it can be an issue with my SQL Server connection string, since I am able to see the data in Visual Studio using Server Explorer, so I'm at a real loss.
I am using Identity 2.1, and I'll paste in the stack trace below. Any help with this will be appreciated!
Stack Trace:
[SqlException (0x80131904): Invalid column name 'UserId'.
Invalid column name 'UserId'.]
System.Data.SqlClient.SqlCommand.b__24(Task1 result) +2452144
System.Threading.Tasks.ContinuationResultTaskFromResultTask
2.InnerInvoke() +77
System.Threading.Tasks.Task.Execute() +60
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +11846300
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +53
System.Runtime.CompilerServices.TaskAwaiter1.GetResult() +28
System.Data.Entity.Utilities.CultureAwaiter
1.GetResult() +123
System.Data.Entity.Core.EntityClient.Internal.d__c.MoveNext() +447
[EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.]
System.Data.Entity.Core.EntityClient.Internal.d__c.MoveNext() +549
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +11846300
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +53
System.Runtime.CompilerServices.TaskAwaiter1.GetResult() +28
System.Data.Entity.Utilities.CultureAwaiter
1.GetResult() +123
System.Data.Entity.Core.Objects.Internal.d__01.MoveNext() +2429
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +11846300
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +53
System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() +28
System.Data.Entity.Utilities.CultureAwaiter1.GetResult() +123
System.Data.Entity.Core.Objects.<ExecuteInTransactionAsync>d__3d
1.MoveNext() +1543
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +11846300
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +53
System.Runtime.CompilerServices.ConfiguredTaskAwaiter.GetResult() +28
System.Data.Entity.SqlServer.d__91.MoveNext() +626
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +11846300
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +53
System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() +28
System.Data.Entity.Utilities.CultureAwaiter1.GetResult() +123
System.Data.Entity.Core.Objects.<GetResultsAsync>d__e.MoveNext() +1088
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +11846300
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +53
System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() +28
System.Data.Entity.Utilities.CultureAwaiter1.GetResult() +123
System.Data.Entity.Internal.<FirstMoveNextAsync>d__0.MoveNext() +590
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +11846300
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +53
System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() +28
System.Data.Entity.Utilities.CultureAwaiter1.GetResult() +66
System.Data.Entity.Infrastructure.<FirstOrDefaultAsync>d__25
1.MoveNext() +463
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +11846300
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +53
System.Runtime.CompilerServices.TaskAwaiter1.GetResult() +28
Microsoft.AspNet.Identity.CultureAwaiter
1.GetResult() +123
Microsoft.AspNet.Identity.Owin.d__29.MoveNext() +683
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +11846300
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +53
System.Runtime.CompilerServices.TaskAwaiter1.GetResult() +24
CodeFirstExistingDatabase.Controllers.<Login>d__11.MoveNext() in c:\users\kevin\documents\visual studio 2015\Projects\CodeFirstExistingDatabase\CodeFirstExistingDatabase\Controllers\AccountController.cs:78
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +11846300
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +53
System.Runtime.CompilerServices.TaskAwaiter.GetResult() +26
System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +61
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +114
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +66
System.Web.Mvc.Async.WrappedAsyncResult
1.CallEndDelegate(IAsyncResult asyncResult) +47
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +136
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +117
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +44
System.Web.Mvc.Async.WrappedAsyncResult
1.CallEndDelegate(IAsyncResult asyncResult) +47
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +136
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +72
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult
1.CallEndDelegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9720041
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155