indy多线程创建ado连接,创建多个连接后,比如10个,发现sqlserver中有10个该数据库的连接,然后我清除几个连接,但发现sqlserver还是10个,并没释放,但当我把10个都Connection都释放后,sqlserver的连接却都释放了,是什么问题??
也就是说sqlserver中保留了最大数量创建的连接,直到这些连接都释放后才全部释放?我使用的是1个udl连接sqlserver
indy控件名servertype
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 clickprocedure 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;请高人 指点
也就是说sqlserver中保留了最大数量创建的连接,直到这些连接都释放后才全部释放?我使用的是1个udl连接sqlserver
indy控件名servertype
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 clickprocedure 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;请高人 指点
解决方案 »
- delphi7调用存储过程失败。
- 关于ado连接 anywhere8.0问题
- Excel导入导出,包括文本和格式,合并单元格
- case语句如何判断一个变量的值?
- 急散分三:想注册一个商标,加上一个公司名号,不知有没有过来人可以提醒一下
- 小小生日快乐!
- tree数据结构存取,想借用TTreeNodes,但是不成功,还有其它现成的tree结构能用吗?
- ColorToRGB反过来:如何将LongInt转化为TColor?
- 100分献上:请问我对Paradox表的结构修改并保存了之后,为什么原表的所有记录都没了,系统在Database Desktop\PrivDir目录下建了一个相同的Key*.bd文件。如何恢复原表?
- 谁有BU Tools的注册码?(空)
- 救命的问题!急!急!急!急!急!急!急!
- 初学DELPHI,请问各位如何引用包中的类?
改成Client.MYConn.free;试一试
client.MYQuery.Close;
client.MYQuery.SQL.Text := 'select * from BJYY_D_UpData where
client.MYQuery.Open;
client.MYQuery.Append;
client.MYQuery.FieldByName('ID').AsString :=
....
....
client.MYQuery.Post;
client.MYConn.CommitTrans;------------------------------------
ccdarkness(亲亲我的宝贝) ( ) 信誉:100 2007-7-30 23:33:55 得分: 0
freeandnil(Client.MYConn);
改成Client.MYConn.free;试一试 ------------
以前就是这样写的,也不行.-----------------------------------
aniugee(阿牛) ( ) 信誉:100 2007-07-31 08:38:06 得分: 0
为什么不让多个线程去连接一个创建过的TAdoconnection呢,请高手分析一下这两种方法的区别!
-------------------------
这样多个连接去连接1个connection可能会有问题吧,具体什么问题高人解答吧:0
Client.MYQuery通过TAdoconnection连接到数据库,可以直接写
Client.MYQuery.ConnectionString := 'FILE NAME=' + ExtractFileDir(application.ExeName) +
'\bjyy.udl';
TIdPeerThread(List.Items[i]).Data := nil;这个就是结束的哦