我正在使用Enterprise Library的数据访问块。
我的代码正在进行大批量更新,但对于我们的一个客户,它总是因以下例外之一而失败:
System.ArgumentOutOfRangeException: The StatementType enumeration value, 4, is invalid.
Parameter name: StatementType
at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
和
System.InvalidOperationException: Invalid operation. The connection is closed. at
System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) at
System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) at
System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) at
System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping) at
System.Data.Common.DbDataAdapter.Update(DataTable dataTable) at
Microsoft.Practices.EnterpriseLibrary.Data.Database.DoUpdateDataSet(UpdateBehavior behavior, DataSet dataSet, String tableName, IDbCommand insertCommand, IDbCommand updateCommand, IDbCommand deleteCommand, Nullable`1 updateBatchSize) at
Microsoft.Practices.EnterpriseLibrary.Data.Database.UpdateDataSet(DataSet dataSet, String tableName, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand, UpdateBehavior updateBehavior, Nullable`1 updateBatchSize) at
答案 0 :(得分:1)
我已经在互联网上搜索了一段时间,却无法找到这些错误的含义或如何修复它们。现在我终于找到了答案,我正在分享它。
错误总是在10分钟后发生。它实际上是超时。
提高transactionScope.TransactionOptions.Timeout
的价值没有帮助;检查MSDTC是否配置正确也无济于事。
我通过插入以下内容来实现它:
<system.transactions>
<machineSettings maxTimeout="20:00:00"/>
</system.transactions>
进入 machine.config 文件,可在此处找到:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config
希望有一天能帮助别人......