不能在手动或分布事务方式下创建新的连接(线程中批量执行SQL语句)(200分)

  • 主题发起人 主题发起人 银雨辰
  • 开始时间 开始时间

银雨辰

Unregistered / Unconfirmed
GUEST, unregistred user!
线程中批量执行SQL语句时<br>提示错误“不能在手动或分布事务方式下创建新的连接。”<br>确定 再F9<br>提示错误“在异步运行时,操作不能被执行。”<br>确定 再F9<br>提示错误“ITransaction::Commit或ITransaction::Abort被调用,并且对象处于Zombie状态。”<br>确定 再F9<br>提示地址出错(borlndmm.dll)!
 
部分代码:<br>&nbsp; TRunExeSQLStrList = Class(TThread)<br>&nbsp; Private<br>&nbsp; Protected<br>&nbsp; &nbsp; Procedure Execute; Override;<br>&nbsp; &nbsp; Procedure RunExeSQL;<br>&nbsp; Public<br>&nbsp; &nbsp; Constructor Create;<br>&nbsp; End;<br>{<br>****************************** TRunExeSQLStrList *******************************<br>}<br><br>Constructor TRunExeSQLStrList.Create;<br>Begin<br>&nbsp; RunSQL := False; //全局 信号量,为False是禁止创建该线程<br>&nbsp; Inherited Create(False); //创建即执行<br>&nbsp; FreeOnTerminate := True; //执行完即销毁<br>End;<br><br>Procedure TRunExeSQLStrList.Execute;<br>Begin<br>&nbsp; If Not Terminated Then<br>&nbsp; &nbsp; RunExeSQL;<br>End;<br><br>Procedure TRunExeSQLStrList.RunExeSQL;<br>Begin &nbsp;//SQLStrListA、SQLStrListB 为全局变量 交换存储要执行的SQL语句 <br>&nbsp; If LockSQL Then //SQLStrListA 为活动的<br>&nbsp; Begin<br>&nbsp; &nbsp; Try<br>&nbsp; &nbsp; &nbsp; LockSQL := False; //切换 SQLStrListB 为活动的 以便执行 SQLStrListA 中SQL语句<br>&nbsp; &nbsp; &nbsp; If SQLStrListA.Count &gt; 0 Then<br>&nbsp; &nbsp; &nbsp; &nbsp; ExeListSQL(@SQLStrListA); //*********执行此处出错<br>//ExeListSQL 为我的动态链接库引出过程 代码附在后面<br>&nbsp; &nbsp; Finally<br>&nbsp; &nbsp; &nbsp; SQLStrListA.Clear;<br>&nbsp; &nbsp; End;<br>&nbsp; End;<br><br>&nbsp; If Not LockSQL Then //SQLStrListB 为活动的<br>&nbsp; Begin<br>&nbsp; &nbsp; Try<br>&nbsp; &nbsp; &nbsp; LockSQL := True; //切换 SQLStrListA 为活动的 以便执行 SQLStrListB 中SQL语句<br>&nbsp; &nbsp; &nbsp; If SQLStrListB.Count &gt; 0 Then<br>&nbsp; &nbsp; &nbsp; &nbsp; ExeListSQL(@SQLStrListB);<br>&nbsp; &nbsp; Finally<br>&nbsp; &nbsp; &nbsp; SQLStrListB.Clear;<br>&nbsp; &nbsp; &nbsp; Sleep(5000);<br>&nbsp; &nbsp; &nbsp; RunSQL := True; //线程TRunExeSQLStrList创建触发信号<br>&nbsp; &nbsp; End;<br>&nbsp; End;<br>End;<br><br><br>Function ExeListSQL(ASQL: PTStr): Boolean; StdCall; External 'DataControl.DLL';<br>//PTStr = ^TStrings;<br>//ExeListSQL不附在线程中执行是正常的,函数代码如下:<br>Function TDM.ProtExeSQL(ASQL: PTStr): Boolean;<br>Var<br>&nbsp; I, J: Integer;<br>&nbsp; Str: String;<br>Begin<br>&nbsp; Result := True;<br>&nbsp; J := ASQL^.Count;<br>&nbsp; If J = 0 Then<br>&nbsp; &nbsp; Exit;<br>&nbsp; If stClosed In DM.ADOCon.State Then<br>&nbsp; &nbsp; DM.ADOCon.Open;<br>&nbsp; DM.ADOQ.Close;<br>&nbsp; DM.ADOCon.BeginTrans;<br>&nbsp; Try &nbsp; &nbsp;<br>&nbsp; &nbsp; J := ASQL^.Count;<br>&nbsp; &nbsp; DM.ADOQ.SQL.Clear;<br>&nbsp; &nbsp; For I := 0 To J - 1 Do<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; If I &lt; 10 Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Str := #13 + ASQL^;<br>&nbsp; &nbsp; &nbsp; DM.ADOQ.SQL.Add(ASQL^);<br>&nbsp; &nbsp; &nbsp; If DM.ADOQ.SQL.Count &gt; 100 Then<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; DM.ADOQ.ExecSQL;<br>&nbsp; &nbsp; &nbsp; &nbsp; DM.ADOQ.SQL.Clear;<br>&nbsp; &nbsp; &nbsp; End;<br>&nbsp; &nbsp; End;<br>&nbsp; &nbsp; If DM.ADOQ.SQL.Count &gt; 0 Then<br>&nbsp; &nbsp; &nbsp; DM.ADOQ.ExecSQL;<br>&nbsp; &nbsp; DM.ADOCon.CommitTrans;<br>&nbsp; Except<br>&nbsp; &nbsp; DM.ADOCon.RollbackTrans;<br>&nbsp; &nbsp; MessageBox(0, PChar('&amp;Ecirc;&amp;yacute;&amp;frac34;&amp;Yacute;&amp;iquest;&amp;acirc;&amp;sup2;&amp;Ugrave;×÷&amp;Ouml;&amp;acute;&amp;ETH;&amp;ETH;&amp;sup3;&amp;ouml;&amp;acute;í!' + Str), '&amp;Ecirc;&amp;yacute;&amp;frac34;&amp;Yacute;&amp;iquest;&amp;acirc;&amp;sup2;&amp;Ugrave;×÷', MB_ICONERROR);<br>&nbsp; &nbsp; Result := False;<br>&nbsp; End;<br><br>&nbsp; DM.ADOQ.Close;<br>End;
 
这么没人回答?!<br>难道5.1你们都放假了吗?
 
后退
顶部