多线程数据库写操作出现连接占线导致另一个命令错误(急...急....) ( 积分: 50 )

  • 主题发起人 主题发起人 天涯一客
  • 开始时间 开始时间

天涯一客

Unregistered / Unconfirmed
GUEST, unregistred user!
unit&nbsp;UQsdate;<br><br>interface<br><br>uses<br>&nbsp;&nbsp;Classes,SysUtils,Math;<br><br>type<br>&nbsp;&nbsp;querysendThread&nbsp;=&nbsp;class(TThread)<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Private&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;protected<br>&nbsp;&nbsp;&nbsp;procedure&nbsp;sendnumber;<br>&nbsp;&nbsp;&nbsp;procedure&nbsp;Receivedata;<br>&nbsp;&nbsp;&nbsp;procedure&nbsp;query;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Execute;&nbsp;override;<br>&nbsp;&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;constructor&nbsp;create;<br>&nbsp;&nbsp;end;<br><br>implementation<br>&nbsp;uses&nbsp;main,dmpublic,dataDM,publicdata;<br>{&nbsp;Important:&nbsp;Methods&nbsp;and&nbsp;properties&nbsp;of&nbsp;objects&nbsp;in&nbsp;visual&nbsp;components&nbsp;can&nbsp;only&nbsp;be<br>&nbsp;&nbsp;used&nbsp;in&nbsp;a&nbsp;method&nbsp;called&nbsp;using&nbsp;Synchronize,&nbsp;for&nbsp;example,<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Synchronize(UpdateCaption);<br><br>&nbsp;&nbsp;and&nbsp;UpdateCaption&nbsp;could&nbsp;look&nbsp;like,<br><br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;querysendThread.UpdateCaption;<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form1.Caption&nbsp;:=&nbsp;'Updated&nbsp;in&nbsp;a&nbsp;thread';<br>&nbsp;&nbsp;&nbsp;&nbsp;end;&nbsp;}<br><br>{&nbsp;querysendThread&nbsp;}<br><br>constructor&nbsp;querysendThread.create;<br>begin<br>&nbsp;&nbsp;inherited&nbsp;create(true);<br>&nbsp;&nbsp;&nbsp;Priority&nbsp;:=tpNormal;<br>//&nbsp;&nbsp;Priority&nbsp;:=&nbsp;tpLower;<br>end;<br><br>procedure&nbsp;querysendThread.Execute;<br>var<br>sql2:string;<br>times,showtime,n,j,i,k,b:integer;<br>begin<br><br>FrmMain.Timer2.Enabled&nbsp;:=false;<br>b:=0;<br>&nbsp;sql2:='select&nbsp;time&nbsp;from&nbsp;action_set&nbsp;where&nbsp;loginName='''+yhm+'''&nbsp;and&nbsp;userpassword='''+pass+'''';<br>&nbsp;opendate(data.q4&nbsp;,&nbsp;sql2);<br>times:=data.q4.fieldbyName('time').AsInteger;<br><br>begin<br>&nbsp;&nbsp;dm.ShuaxingStoredProc.Parameters&nbsp;.ParamByName('@loginName').Value:=yhm&nbsp;;<br>&nbsp;&nbsp;&nbsp;dm.ShuaxingStoredProc.Parameters.ParamByName('@password').Value:=pass&nbsp;;<br>&nbsp;&nbsp;dm.ShuaxingStoredProc.Open&nbsp;;<br><br>with&nbsp;dm.ShuaxingStoredProc&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;first;<br>&nbsp;&nbsp;while&nbsp;not&nbsp;Eof&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Synchronize(sendnumber)&nbsp;;&nbsp;//送数<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecSQLdate(dm.UPdataADOQuery&nbsp;,'update&nbsp;RM_def&nbsp;set&nbsp;change=0&nbsp;where&nbsp;Com_addr='+addr&nbsp;);<br>&nbsp;&nbsp;<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Synchronize(query);&nbsp;//查询<br>&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Synchronize(Receivedata)<br>&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;ExecSQLdate(dm.UPdataADOQuery&nbsp;,'update&nbsp;RM_def&nbsp;set&nbsp;showtimes='+inttostr(showTime)+'&nbsp;where&nbsp;com_addr='+FieldByName('Com_addr').AsString);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecSQLdate(dm.UPdataADOQuery&nbsp;,'update&nbsp;other&nbsp;set&nbsp;temperature1=0,&nbsp;temperature=0,&nbsp;temperature2=0,&nbsp;urgent=0,air1=0,air2=0,air3=0,Cardtype=0&nbsp;where&nbsp;com_addr='+addr);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;next<br>&nbsp;&nbsp;end;<br>&nbsp;<br>end;<br>&nbsp;dm.ShuaxingStoredProc.Close;<br>FrmMain.Timer2.Enabled&nbsp;:=true;<br><br>end;<br><br>procedure&nbsp;querysendThread.Receivedata;<br>var<br>&nbsp;&nbsp;tep,tep1:byte;<br>&nbsp;&nbsp;paritybit:byte;<br>&nbsp;&nbsp;i,j:integer;<br>&nbsp;&nbsp;TMinute:Extended&nbsp;;<br>&nbsp;&nbsp;sql,O_sql,sql_Rm,dz:string;<br>&nbsp;&nbsp;sql_so,sql_en:string;<br>begin<br>sql:='update&nbsp;serve&nbsp;set';<br>O_sql:='update&nbsp;other&nbsp;set';<br>sql_Rm:='update&nbsp;RM_def&nbsp;set&nbsp;showtimes=0,comok=1';<br>sql_so:='select&nbsp;Fkey,Door,safe_door,serve,someone&nbsp;from&nbsp;serve_other_view&nbsp;where&nbsp;com_addr=';<br><br>&nbsp;ExecSQLdate(dm.UPdataADOQuery&nbsp;,sql_en);<br>&nbsp;&nbsp;&nbsp;ExecSQLdate(dm.UPdataADOQuery&nbsp;,sql);<br>&nbsp;&nbsp;ExecSQLdate(dm.UPdataADOQuery&nbsp;,O_sql);<br>&nbsp;&nbsp;ExecSQLdate(dm.UPdataADOQuery&nbsp;,sql_Rm);<br>&nbsp;&nbsp;except<br>&nbsp;&nbsp;exit;<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;end;<br><br><br>//------------送数----------------------<br>&nbsp;procedure&nbsp;&nbsp;querysendThread.sendnumber;<br>var<br>&nbsp;&nbsp;sbuf:array[0..20]&nbsp;of&nbsp;byte;<br>&nbsp;&nbsp;paritybit:byte;<br>&nbsp;&nbsp;i:integer;<br>begin<br>sbuf[0]:=85;<br>sbuf[1]:=50;<br>sbuf[2]:=48;<br>sbuf[3]:=49;<br>//取通讯地址&nbsp;&nbsp;根据房间号找到地址号<br>sbuf[4]:=asc(HexaToDecimal(copy(inttohex(adr,2),1,1)));<br>sbuf[5]:=asc(HexaToDecimal(copy(inttohex(adr,2),2,1)));<br>sbuf[6]:=asc(RM_STA_Tmp);<br>sbuf[7]:=asc(RM_STATUS);<br>sbuf[8]:=48;<br>sbuf[9]:=49;<br>sbuf[10]:=48;<br>sbuf[11]:=asc(hexatodecimal(copy(inttohex(RM_SETTEMP&nbsp;*10,3),1,1)));<br>sbuf[12]:=asc(hexatodecimal(copy(inttohex(RM_SETTEMP*10,3),2,1)));<br>sbuf[13]:=asc(hexatodecimal(copy(inttohex(RM_SETTEMP*10,3),3,1)));<br>sbuf[14]:=56;<br>sbuf[15]:=asc(AirFan);<br>sbuf[16]:=56;<br>sbuf[17]:=asc(AirFan1);<br>paritybit:=sbuf[1];<br>for&nbsp;i:=2&nbsp;to&nbsp;17&nbsp;do<br>paritybit:=paritybit&nbsp;xor&nbsp;sbuf;<br>sbuf[18]:=asc((paritybit&nbsp;and&nbsp;$f0)&nbsp;div&nbsp;16);<br>sbuf[19]:=asc((paritybit&nbsp;and&nbsp;$f)&nbsp;mod&nbsp;16);<br>sbuf[20]:=13;<br>FrmMain.ComPort.write(sbuf,Length(sbuf));<br>end;<br><br><br>procedure&nbsp;querysendThread.query;<br>var<br>&nbsp;&nbsp;sbuf:array[0..8]of&nbsp;byte;<br>&nbsp;&nbsp;paritybit:byte;<br>begin<br>sbuf[0]:=85;<br>sbuf[1]:=51;<br>sbuf[2]:=48;<br>sbuf[3]:=48;<br>sbuf[4]:=asc(HexaToDecimal(copy(inttohex(Strtoint(addr),2),1,1)));<br>sbuf[5]:=asc(HexaToDecimal(copy(inttohex(Strtoint(addr),2),2,1)));<br>paritybit:=sbuf[1]&nbsp;xor&nbsp;sbuf[2]xor&nbsp;sbuf[3]&nbsp;xor&nbsp;sbuf[4]&nbsp;xor&nbsp;sbuf[5];<br>sbuf[6]:=asc((paritybit&nbsp;and&nbsp;$f0)div&nbsp;16);<br>sbuf[7]:=asc(paritybit&nbsp;and&nbsp;$f&nbsp;);<br>sbuf[8]:=13;<br>FrmMain.ComPort.write(sbuf,Length(sbuf));<br>end;<br><br>end.<br><br><br>procedure&nbsp;ExecSQLdate(query:Tadoquery;sql:string);<br>begin<br>&nbsp;&nbsp;query.close;<br>&nbsp;&nbsp;query.SQL.Clear;<br>&nbsp;&nbsp;query.SQL.add(sql);<br>&nbsp;&nbsp;query.ExecSQL;<br>end;<br><br>procedure&nbsp;opendate(query:Tadoquery;sql:string);<br>begin<br>&nbsp;&nbsp;query.close;<br>&nbsp;&nbsp;query.SQL.Clear;<br>&nbsp;&nbsp;query.SQL.add(sql);<br>&nbsp;&nbsp;query.Prepared;<br>&nbsp;&nbsp;query.Open;<br>end;<br>请问各位市手,我在使用以上语句调用时什突发情出现"连接占线导致另一个命令"错误<br>并停在ADODB的<br><br>&nbsp;if&nbsp;not&nbsp;Assigned(Recordset)&nbsp;then&nbsp;&nbsp;(第3472行)<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;InitializeConnection;<br>&nbsp;&nbsp;&nbsp;&nbsp;InitializeRecordset;<br>&nbsp;&nbsp;&nbsp;&nbsp;Recordset.Open(Source,&nbsp;ActiveConnection,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CursorTypeValues[FCursorType],&nbsp;LockTypeValues[FLockType],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Integer(CommandTypeValues[CommandType])&nbsp;+&nbsp;ExecuteOptionsToOrd(ExecuteOptions));<br>&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;Recordset.State&nbsp;=&nbsp;adStateClosed&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FRecordsetObject&nbsp;:=&nbsp;Recordset.NextRecordset(VarRecsAffected);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;Recordset&nbsp;=&nbsp;nil&nbsp;then&nbsp;Abort;<br>&nbsp;&nbsp;&nbsp;&nbsp;except<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DatabaseError(SNoResultSet,&nbsp;Self);<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;end&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;EnableEvents;<br>&nbsp;&nbsp;if&nbsp;(eoAsyncExecute&nbsp;in&nbsp;ExecuteOptions)&nbsp;and&nbsp;((Recordset.State&nbsp;and&nbsp;adStateExecuting)&nbsp;&lt;&gt;&nbsp;0)&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;SetState(dsOpening);<br>&nbsp;&nbsp;inherited&nbsp;OpenCursor(False);<br>end;<br><br><br>请问高手,要怎么样才能很好的解决这个问题,
 
每个线程使用不同的data.up_RM_def,或者手工申请再释放。
 
后退
顶部