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