Bor*_*itz 22 c# entity-framework azure-sql-database
升级到Entity Framework 6后,我们实现了自己的DbExecutionStrategy.除了现有的SqlAzureExecutionStrategy,我们的策略还会记录异常.事实证明,每15-30分钟实体框架抛出内部SqlException
System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'CreatedOn'.
这是一个内部错误.如果某些表上存在CreatedOn列,EF似乎会进行一些定期检查.是否有任何优雅的方法来防止抛出此异常?
这是一个调用堆栈:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, ref Boolean dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, ref Task task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, ref Task task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(Func`1 operation, TInterceptionContext interceptionContext, Action`1 executing, Action`1 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
Run Code Online (Sandbox Code Playgroud)
Bor*_*itz 39
过去的实体框架曾经在__MigrationHistory表中有一个"CreatenOn"列.
每次AppDomain启动时,它都会检查数据库是否需要迁移.EF实际上尝试读取"CreatedOn"列,但显然会失败,并记录异常.EF在此检查周围有一个丑陋的try/catch所有块,如果抛出异常(列缺失),那么它不会尝试"迁移"CreatedOn列.
目前没有办法禁用该检查,只是不记录它...
就我而言,发生此错误是因为我已更改Visual Studio Debug Exceptions 设置以中断所有异常(或比默认配置更多的异常)。重置Visual Studio的所有设置后,错误不再发生,我的应用程序按预期正常运行。
问题是实体框架有一个 try/catch 块来处理此错误,以便应用程序在发生此错误时不会停止工作。处理错误后,它会将应用程序返回到正常状态,就像您在自己的应用程序的 try/catch 块中所做的那样。因此,打破这些异常会使我的代码不必要地停止。
当我调试一个复杂的程序时,打破所有异常是必要的,但我应该在我不再需要之后重置调试异常设置。希望这可以帮助其他人经历同样难以捕捉的环境问题。
| 归档时间: |
|
| 查看次数: |
6568 次 |
| 最近记录: |