Как указано в заголовке, я использую многопоточность для запроса данных из DB2. Иногда мои приложения использовали два потока для выполнения этого запроса, и мои приложения выполняли следующее:
2024-12-26 15:29:06 Info : [152] P_IMS_AUTOJOB_HANDLE start
SELECT
*
FROM
SIVIEW.T_IMS_AUTOJOB_LIST
WHERE ID = 26 with ur
2024-12-26 15:29:06 Info : [168] P_IMS_AUTOJOB_HANDLE start
SELECT
*
FROM
SIVIEW.T_IMS_AUTOJOB_LIST
WHERE ID = 26 with ur
2024-12-26 15:29:06 Error : ERROR [58005] [IBM][DB2.NET] SQL0902 An unexpected exception has occurred in Process: 4680 Thread 168 AppDomain: Name:IMS.AutoJob.JobCenter.exe
There are no context policies.
Function: AllocateandLinkStatementHandle
CallStack: at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at IBM.Data.DB2.DB2ConnPool.HandleUnknownErrors(String strFncMsg, Exception exception, Boolean bThrow)
at IBM.Data.DB2.DB2Command.AllocateAndLinkStatementHandle(IntPtr& stmt, IntPtr& pStmtListLink, Boolean& bHostVarParamEnabled, Boolean fInternal)
at IBM.Data.DB2.DB2Command.GetStatementHandle()
at IBM.Data.DB2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method, DB2CursorType reqCursorType, Boolean abortOnOptValueChg, Boolean skipDeleted, Boolean isResultSet, Int32 maxRows, Boolean skipInitialValidation)
at IBM.Data.DB2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method)
at IBM.Data.DB2.DB2Command.ExecuteReader(CommandBehavior behavior)
at IBM.Data.DB2.DB2Command.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior) in /_/Dapper/SqlMapper.cs:line 1066
at Dapper.SqlMapper.d__140`1.MoveNext() in /_/Dapper/SqlMapper.cs:line 1094
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 734
at IMS.Tool.Data.DB.DbHelper.Query[T](String sqlText) in D:\源代码\IMS_System\IMS.Tool.Data\DB\DbHelper.cs:line 84
at IMS.Tool.Data.DB.DBFactoryActive.Query[T](String sqlText) in D:\源代码\IMS_System\IMS.Tool.Data\DB\DBFactoryActive.cs:line 74
at IMS.AutoJob.JobCenter.Dal.AUTOJOBDal.GetJob(Int32 ID) in D:\源代码\IMS_System\IMS.AutoJob.JobCenter\Dal\AUTOJOBDal.cs:line 41
at IMS.AutoJob.JobCenter.FrmMain.ExecSoft(AUTOJOBEntity job) in D:\源代码\IMS_System\IMS.AutoJob.JobCenter\FrmMain.cs:line 176
at IMS.AutoJob.JobCenter.FrmMain.c__DisplayClass13_0.b__0() in D:\源代码\IMS_System\IMS.AutoJob.JobCenter\FrmMain.cs:line 120
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
at System.Threading.Tasks.Task.ExecutionContextCallback(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() InnerException Message: Operation is not valid due to the current state of the object. Check InnerException property for more detail. SQLSTATE=58005
Как указано в заголовке, я использую многопоточность для запроса данных из DB2. Иногда мои приложения использовали два потока для выполнения этого запроса, и мои приложения выполняли следующее: [code]2024-12-26 15:29:06 Info : [152] P_IMS_AUTOJOB_HANDLE start SELECT * FROM SIVIEW.T_IMS_AUTOJOB_LIST WHERE ID = 26 with ur 2024-12-26 15:29:06 Info : [168] P_IMS_AUTOJOB_HANDLE start SELECT * FROM SIVIEW.T_IMS_AUTOJOB_LIST WHERE ID = 26 with ur 2024-12-26 15:29:06 Error : ERROR [58005] [IBM][DB2.NET] SQL0902 An unexpected exception has occurred in Process: 4680 Thread 168 AppDomain: Name:IMS.AutoJob.JobCenter.exe There are no context policies. Function: AllocateandLinkStatementHandle CallStack: at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo) at System.Environment.get_StackTrace() at IBM.Data.DB2.DB2ConnPool.HandleUnknownErrors(String strFncMsg, Exception exception, Boolean bThrow) at IBM.Data.DB2.DB2Command.AllocateAndLinkStatementHandle(IntPtr& stmt, IntPtr& pStmtListLink, Boolean& bHostVarParamEnabled, Boolean fInternal) at IBM.Data.DB2.DB2Command.GetStatementHandle() at IBM.Data.DB2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method, DB2CursorType reqCursorType, Boolean abortOnOptValueChg, Boolean skipDeleted, Boolean isResultSet, Int32 maxRows, Boolean skipInitialValidation) at IBM.Data.DB2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method) at IBM.Data.DB2.DB2Command.ExecuteReader(CommandBehavior behavior) at IBM.Data.DB2.DB2Command.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior) in /_/Dapper/SqlMapper.cs:line 1066 at Dapper.SqlMapper.d__140`1.MoveNext() in /_/Dapper/SqlMapper.cs:line 1094 at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 734 at IMS.Tool.Data.DB.DbHelper.Query[T](String sqlText) in D:\源代码\IMS_System\IMS.Tool.Data\DB\DbHelper.cs:line 84 at IMS.Tool.Data.DB.DBFactoryActive.Query[T](String sqlText) in D:\源代码\IMS_System\IMS.Tool.Data\DB\DBFactoryActive.cs:line 74 at IMS.AutoJob.JobCenter.Dal.AUTOJOBDal.GetJob(Int32 ID) in D:\源代码\IMS_System\IMS.AutoJob.JobCenter\Dal\AUTOJOBDal.cs:line 41 at IMS.AutoJob.JobCenter.FrmMain.ExecSoft(AUTOJOBEntity job) in D:\源代码\IMS_System\IMS.AutoJob.JobCenter\FrmMain.cs:line 176 at IMS.AutoJob.JobCenter.FrmMain.c__DisplayClass13_0.b__0() in D:\源代码\IMS_System\IMS.AutoJob.JobCenter\FrmMain.cs:line 120 at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.Execute() at System.Threading.Tasks.Task.ExecutionContextCallback(Object obj) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution) at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() InnerException Message: Operation is not valid due to the current state of the object. Check InnerException property for more detail. SQLSTATE=58005 [/code] Как это исправить? Есть идея. Есть идея.