title: Upgraded EF5 to EF 6 and now get "Cannot find the object because it does not exist or you do not have permissions."
body: <p>I've got a main web application project using a referenced class library that uses EF code first. In the main web application I've also got several .edmx files. This is a production app with real data using automatic migrations (MigrateDatabaseToLatestVersion). </p>
  
  <p>I just upgraded from EF 5 to EF 6. There were no class/context changes at all between upgrading. I simply upgraded and fixed my .edmx files. No compile time errors. Yet when I try my main app I get the following error:</p>
  
  <blockquote>
    <p>Cannot find the object "dbo.FormItemResponseFormItemAnswers" because
    it does not exist or you do not have permissions.</p>
  </blockquote>
  
  <p>Now I've double checked my database and the table should and does in fact exist and the login uses to connect has dbo permissions on the database as they did before the upgrade. So I have no idea why I am getting this error. Nothing changed. The stack trace looks like so:</p>
  
  <blockquote>
    <p>[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, Action<code>1 wrapCloseInAction) +1767866
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action</code>1 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&amp; dataReady) +1691
       System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) +869
       System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource<code>1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +410
       System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +160
       System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.&lt;NonQuery&gt;b__0(DbCommand t, DbCommandInterceptionContext</code>1 c) +36
       System.Data.Entity.Infrastructure.Interception.InternalDispatcher<code>1.Dispatch(TTarget target, Func</code>3 operation, TInterceptionContext interceptionContext, Action<code>3 executing, Action</code>3 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(IEnumerable<code>1 migrationStatements, DbTransaction transaction, DbInterceptionContext interceptionContext) +110
       System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable</code>1 migrationStatements, DbConnection connection) +799
       System.Data.Entity.Migrations.&lt;>c__DisplayClass30.b__2e() +66
       System.Data.Entity.SqlServer.&lt;>c__DisplayClass1.b__0() +34
       System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func<code>1 operation) +251
       System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) +196
       System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable</code>1 migrationStatements, DbTransaction existingTransaction) +326
       System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable<code>1 migrationStatements) +39
       System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable</code>1 migrationStatements) +42
       System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable<code>1 operations, IEnumerable</code>1 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(IEnumerable<code>1 pendingMigrations, String targetMigrationId, String lastMigrationId) +741
       System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable</code>1 pendingMigrations, String targetMigrationId, String lastMigrationId) +59
       System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration) +888
       System.Data.Entity.Migrations.&lt;>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.MigrateDatabaseToLatestVersion<code>2.InitializeDatabase(TContext context) +154
       System.Data.Entity.Internal.&lt;&gt;c__DisplayClassf</code>1.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.RetryAction<code>1.PerformAction(TInput input) +143
       System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action</code>1 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.InternalSet<code>1.Initialize() +137
       System.Data.Entity.Internal.Linq.InternalSet</code>1.get_InternalContext() +38
       System.Data.Entity.Infrastructure.DbQuery<code>1.System.Linq.IQueryable.get_Provider() +99
       System.Linq.Queryable.Where(IQueryable</code>1 source, Expression`1 predicate) +63</p>
  </blockquote>
  
  <p>I haven't found anyone else with this problem. Can someone shed some light? I've no clue what to do and the usual google reveals mostly SQL errors with having no relation to EF.</p>
  
  <p>Again nothing in the context/objects changed nor were any manual changes done to the database. I double checked my source control. I can't tell from the stack trace if it's trying to run a migration or not but I use automatic migration and it shouldn't be attempting to migrate because nothing changed.</p>
  
  <p>EDIT: I know the _MigrationHistory table stores the EF version number in it and all mine are currently 5.0.0.net45. Is it possible it's trying to create a new migration history record for v6? But again, no context change I don't know what's it's trying to do with that table.</p>