Upgraded EF5 to EF 6 and now get "Cannot find the object because it does not exist or you do not have permissions."

asp.net-mvc c# entity-framework entity-framework-6 entity-framework-6.1

Question

I have a main web application project that makes use of a class library that is referenced and uses EF code first. I also have a number of.edmx files in the main web application. This app uses automatic migrations and is in production with actual data (MigrateDatabaseToLatestVersion).

I recently moved from an EF 5 to an EF 6. Between upgrades, there were zero modifications to the class or context. My.edmx files were simply upgraded and repaired. No compile-time mistakes. Nevertheless, when I use my primary app, I encounter the following error:

Cannot find the object "dbo.FormItemResponseFormItemAnswers" because it does not exist or you do not have permissions.

Now that I've again checked my database, I can confirm that the table does indeed exist and that the login used to connect has the same dbo permissions as it did before to the upgrade. Therefore, I am unsure of the cause of this problem. Inertia persisted. The stack trace appears as follows:

[SqlException (0x80131904): Cannot find the object "dbo.FormItemResponseFormItemAnswers" because it does not exist or you do not have permissions.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +1767866 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +5352418 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +244 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1691 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) +869 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +410 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +160 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext1 c) +36 System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch(TTarget target, Func3 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed) +138 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext) +476 System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery() +177 System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement, DbInterceptionContext interceptionContext) +307 System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement, DbInterceptionContext interceptionContext) +59 System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable1 migrationStatements, DbTransaction transaction, DbInterceptionContext interceptionContext) +110 System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable1 migrationStatements, DbConnection connection) +799 System.Data.Entity.Migrations.<>c__DisplayClass30.b__2e() +66 System.Data.Entity.SqlServer.<>c__DisplayClass1.b__0() +34 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func1 operation) +251 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) +196 System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable1 migrationStatements, DbTransaction existingTransaction) +326 System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable1 migrationStatements) +39 System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable1 migrationStatements) +42 System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable1 operations, IEnumerable1 systemOperations, Boolean downgrading, Boolean auto) +1335 System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading) +1358 System.Data.Entity.Migrations.Infrastructure.MigratorBase.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading) +64 System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable1 pendingMigrations, String targetMigrationId, String lastMigrationId) +741 System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable1 pendingMigrations, String targetMigrationId, String lastMigrationId) +59 System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration) +888 System.Data.Entity.Migrations.<>c__DisplayClassc.b__b() +38 System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +516 System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +42 System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) +136 System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update() +33 System.Data.Entity.MigrateDatabaseToLatestVersion2.InitializeDatabase(TContext context) +154 System.Data.Entity.Internal.<>c__DisplayClassf1.b__e() +165 System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +110 System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +660 System.Data.Entity.Internal.LazyInternalContext.b__4(InternalContext c) +31 System.Data.Entity.Internal.RetryAction1.PerformAction(TInput input) +143 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action1 action) +292 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +123 System.Data.Entity.Internal.InternalContext.Initialize() +41 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +39 System.Data.Entity.Internal.Linq.InternalSet1.Initialize() +137 System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext() +38 System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider() +99 System.Linq.Queryable.Where(IQueryable1 source, Expression`1 predicate) +63

No one else I've found has this issue. Someone please offer some insight. I have no idea what to do, and a simple search on Google turns up largely SQL issues that have nothing to do with EF.

Again, neither the context nor the objects changed, and the database was not manually altered. My source control system was examined twice. I'm not sure if it's trying to execute a migration or not based on the stack trace, but I use automatic migration, so it shouldn't be trying to migrate because nothing changed.

EDIT: I am aware that the _MigrationHistory database has information on the EF version, and all of mine are now 5.0.0.net45. Is it conceivable that it's attempting to make a brand-new v6 migration history record? but once more, no context shift I'm not sure what the purpose of that table is.

1
2
5/30/2014 4:37:28 PM

Popular Answer

The usage of automatic migrations outside of testing and development is not recommended. Additionally, instead of using the actual production database, you should execute your upgrading procedure against a replica or clone that is similar to production. Disabling automated migration and requiring a regular migration with the>Add-Migration after that>Update-Database could address this problem.

0
5/30/2014 5:42:14 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow