幸
幸福鸟
Unregistered / Unconfirmed
GUEST, unregistred user!
indy多线程创建ado连接,创建多个连接后,比如10个,发现sqlserver中有10个该数据库的连接,然后我清除几个连接,但发现sqlserver还是10个,并没释放,但当我把10个都Connection都释放后,sqlserver的连接却都释放了,是什么问题??<br>也就是说sqlserver中保留了最大数量创建的连接,直到这些连接都释放后才全部释放?<br><br>我使用的是1个udl连接sqlserver<br>indy控件名server<br><br>type<br> TSimpleClient = record<br> id: Cardinal; //系统编号<br> IP: string; //IP<br> Port: integer; //端口<br> LoginTime: string; //登录时间<br> UpdateTime: string; //更新时间<br> DataBackTime: Integer; //监控时间, 超时则断开<br> MYConn: TADOConnection;<br> MYQuery: tadoquery;<br> end;<br> PMyClient = ^TSimpleClient;<br><br>//有客户端连接<br>procedure TfrmShowMain.ServerConnect(AThread: TIdPeerThread);<br>var<br> Client: PMyClient;<br> list: TList;<br> i: integer;<br> Ret: DWord;<br>begin<br> try<br> CoInitialize(nil); //<br> Client := new(PMyClient);<br> Client.id := AThread.ThreadID; <br> Client.IP := AThread.Connection.Socket.Binding.PeerIP;<br> Client.Port := AThread.Connection.Socket.Binding.PeerPort;<br> Client.LoginTime := formatdatetime('yyyy-mm-dd HH:mm:ss', now);<br> Client.UpdateTime := formatdatetime('yyyy-mm-dd HH:mm:ss', now);<br> AThread.Data := Pointer(client); <br><br> Client.MYConn := TAdoconnection.create(nil); //创建的连接<br> Client.MYConn.LoginPrompt := False;<br> Client.MYConn.KeepConnection := True;<br> Client.MYConn.ConnectionString := 'FILE NAME=' + ExtractFileDir(application.ExeName) +<br> '/bjyy.udl';<br> Client.MYQuery := tadoquery.Create(nil);<br> Client.MYQuery.Connection := Client.MYConn;<br> Client.MYConn.Connected := true;<br> AThread.Connection.WriteLn('Welcome');<br> except<br> on E: Exception do<br> begin<br> end;<br> end;<br>end;<br><br>//在某button click<br><br>procedure TfrmShowMain.BitBtn3Click(Sender: TObject);<br>var<br> Client: PMyClient;<br> list: TList;<br> i: integer;<br>begin<br> if not server.Active then<br> exit;<br> List := Server.Threads.LockList;<br> try<br> for i := 0 to List.Count - 1 do<br> begin<br> try<br> Client := Pointer(TIdPeerThread(List.Items).Data);<br> if Client = nil then<br> continue;<br> if inttostr(Client.id) = listview1.Selected.Caption then<br> begin //发现我要断开的ID<br> Client.MYQuery.Close;<br> Client.MYQuery.Free;<br><br> Client.MYConn.Connected := false;<br> freeandnil(Client.MYConn);<br><br> TIdPeerThread(List.Items).Connection.Disconnect;<br> TIdPeerThread(List.Items).Data := nil;<br> FreeMem(Client);<br> CoUnInitialize();<br> exit;<br> end;<br> except<br> on E: Exception do<br> begin<br> end;<br> end;<br> end;<br> finally<br> Server.Threads.UnlockList;<br> end;<br>end;<br><br>请高人 指点