为什么我的多线程程序访问SQL Server数据库时报‘连接占线导致另一个命令’ 我作了一个网关程序多线程访问SQL Server2000数据库。用的是TADOConnection连接数据库。TIdTCPServer接收客户端传来的请求做处理。在TIdTCPServer里动态建立TADOQuery。当数据量不大的时候很正常。但是数据量比较大线程比较多的时候在TADOQuery执行SQL语句的时候就报‘连接占线导致另一个命令’这个错误。请高手帮助分析一下具体问题可能出在什么地方?谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 with TADOQuery.Create(Nil) do try Connection := ADOC;ADOC是TADOConnection //ConnectionString := ADOC.ConnectionString ; //向LogicMsg中加入数据//************************************************************************************************** Close; SQL.Clear; //逻辑机号,流水号,玩发,销售期号,销售时间,有效期数,销售金额,注销金额,是否注销,注码,WinRec的ID字段 SQL.Text := 'insert into LogicMsg values '; SQL.Text := SQL.Text +'('''+MLogic+''','''+MRun+''','''+PN^.PlayName+''','''+PN^.SellTerMCord+''','''+PN^.SellDatetime+''','''+PN^.ValidTermNum+''',' ; SQL.Text := SQL.Text + IntToStr(XSMNY) +','+ IntToStr(ZXMNY) +','''+ PN^.WithDraw +''','''+PN^.Code+''','+'null'+')' ; try ExecSQL ; except on E:Exception do begin LogMsg := '分配逻辑机号'+MLogic+',流水号'+MRun+',入LogicMsg表失败!卡号:'+Pn^.PhoneCordNo+','+XSM+TZM+','+PN^.BetNum+'注,销售期号:'+PN^.SellTerMCord+#10+#13+', 原因:'+E.Message; WriteLog(AThread.ThreadID,ListBox1.Items,LogMsg); WriteErrorLog(AThread.ThreadID,LogMsg); R := '1106'; Edit1.Text := IntToStr(StrToInt(Edit1.Text)+1); AThread.Connection.WriteBuffer(R,Sizeof(R)); Exit; end end; //如果是多期将剩余导入多期表LogicMul if StrToInt(Trim(PN^.ValidTermNum))>1 then begin Close; SQL.Clear; SQL.Text := 'insert into LogicMul values '; // Edit6.Text SQL.Text := SQL.Text +'('''+MLogic+''','''+MRun+''','''+PN^.PlayName+''','''+PN^.SellTerMCord+''','''+PN^.SellDatetime+''','''+IntTostr(StrToInt(PN^.ValidTermNum)-1)+''',' ; try ExecSQL ; except on E:Exception do begin LogMsg := '分配逻辑机号'+MLogic+',流水号'+MRun+','+XSM+TZM+','+PN^.BetNum+'注,入LogicMul库失败!卡号:'+Pn^.PhoneCordNo+',销售期号:'+PN^.SellTerMCord+#10+#13+', 原因:'+E.Message; WriteLog(AThread.ThreadID,ListBox1.Items,LogMsg); WriteErrorLog(AThread.ThreadID,LogMsg); R := '1107'; Edit1.Text := IntToStr(StrToInt(Edit1.Text)+1); AThread.Connection.WriteBuffer(R,Sizeof(R)); Exit; end end; end;//*************************************************************************************************************** finally free; end; 那有可能是你多线程中共同使用一个Connection,访问冲突了。要么在线程中new一个ADOConnection,要么指定那个ADODataSet的ConnectionString属性,用了之后,线程与主线程的Connection是不同的连接 delphi界面层是不是做界面跟用户登陆的 BDE数据库怎么导出XML格式,XML格式怎么导入到BDE数据库里?谢谢!急!!!!! 独立的窗体设计 我有一个图片,在delphi里异常显示 一个有关SQLConnection连接的问题,大虾们快帮忙呀!!! 请问怎样取得SQL SERVER服务器的名称? 写入文本的问题! 关于表更改的问题: 为什么varchar 字段只能读出一部分? 怎样获取form外的鼠标点击事件? 为什么Delphi+SQL采用ADO技术在有些机器上要先配好ODBC才能运行呀,有什么解决方法吗? ado 灾难性故障 。。。。分不多!谢了!
try
Connection := ADOC;ADOC是TADOConnection
//ConnectionString := ADOC.ConnectionString ;
//向LogicMsg中加入数据
//**************************************************************************************************
Close;
SQL.Clear;
//逻辑机号,流水号,玩发,销售期号,销售时间,有效期数,销售金额,注销金额,是否注销,注码,WinRec的ID字段
SQL.Text := 'insert into LogicMsg values ';
SQL.Text := SQL.Text +'('''+MLogic+''','''+MRun+''','''+PN^.PlayName+''','''+PN^.SellTerMCord+''','''+PN^.SellDatetime+''','''+PN^.ValidTermNum+''',' ;
SQL.Text := SQL.Text + IntToStr(XSMNY) +','+ IntToStr(ZXMNY) +','''+ PN^.WithDraw +''','''+PN^.Code+''','+'null'+')' ;
try
ExecSQL ;
except
on E:Exception do
begin
LogMsg := '分配逻辑机号'+MLogic+',流水号'+MRun+',入LogicMsg表失败!卡号:'+Pn^.PhoneCordNo+','+XSM+TZM+','+PN^.BetNum+'注,销售期号:'+PN^.SellTerMCord+#10+#13+', 原因:'+E.Message;
WriteLog(AThread.ThreadID,ListBox1.Items,LogMsg);
WriteErrorLog(AThread.ThreadID,LogMsg);
R := '1106';
Edit1.Text := IntToStr(StrToInt(Edit1.Text)+1);
AThread.Connection.WriteBuffer(R,Sizeof(R));
Exit;
end
end;
//如果是多期将剩余导入多期表LogicMul
if StrToInt(Trim(PN^.ValidTermNum))>1 then
begin
Close;
SQL.Clear;
SQL.Text := 'insert into LogicMul values '; // Edit6.Text
SQL.Text := SQL.Text +'('''+MLogic+''','''+MRun+''','''+PN^.PlayName+''','''+PN^.SellTerMCord+''','''+PN^.SellDatetime+''','''+IntTostr(StrToInt(PN^.ValidTermNum)-1)+''',' ;
try
ExecSQL ;
except
on E:Exception do
begin
LogMsg := '分配逻辑机号'+MLogic+',流水号'+MRun+','+XSM+TZM+','+PN^.BetNum+'注,入LogicMul库失败!卡号:'+Pn^.PhoneCordNo+',销售期号:'+PN^.SellTerMCord+#10+#13+', 原因:'+E.Message;
WriteLog(AThread.ThreadID,ListBox1.Items,LogMsg);
WriteErrorLog(AThread.ThreadID,LogMsg);
R := '1107';
Edit1.Text := IntToStr(StrToInt(Edit1.Text)+1);
AThread.Connection.WriteBuffer(R,Sizeof(R));
Exit;
end
end;
end;
//***************************************************************************************************************
finally
free;
end;
要么在线程中new一个ADOConnection,要么指定那个ADODataSet的ConnectionString属性,用了之后,线程与主线程的Connection是不同的连接