B
bobo101
Unregistered / Unconfirmed
GUEST, unregistred user!
数据库中保存了多个服务器的ip、sid、password、database等字段,需要逐个探测各条记录保存的数据连接是否可连,若逐个测试耗费时间太长,所以我想用多线程来实现,可我是线程编程的菜鸟,请各位大侠帮帮小弟,若能给段简单例程,小弟更是感激不尽!
这几天为此事快憋疯了!
我是在一窗体的主程序中建立的线程,测试数据连结用的是adoconnection
Thrd = class(TThread)
private
{ Private declarations }
FDBInfo: string;
procedure UpdateUI;
protected
procedure Execute;
override;
public
constructor Create(Suspended: Boolean;
DBInfo: string);
end;
var
f_ljqk: Tf_ljqk;
implementation
{$R *.dfm}
constructor Thrd.Create(Suspended: Boolean;
DBInfo: string);
begin
FDBInfo := DBInfo;
end;
procedure Thrd.Execute;
var
ADO: TADOConnection;
begin
//self.FreeOnTerminate:=true;
ADO := TADOConnection.Create(nil);
ADO.Connectionstring := FDBInfo;
ado.CommandTimeout:=10;
ado.ConnectionTimeout:=5;
if ADO.connected then
Synchronize(UpdateUI)
{ Place thread code here }
end;
procedure Thrd.UpdateUI;
begin
//f_ljqk.label1.caption := '数库1成功';
showmessage('数库成功');
end;
procedure Tf_ljqk.FormCreate(Sender: TObject);
var
inifile: TIniFile;
v_Path,dbconstr,v_dbstr: string;
begin
with adoquery1do
begin
while not eofdo
begin
v_dbstr:='Provider=SQLOLEDB.1;Password='+trim(FieldByName('loadpwd').AsString)+';'+
'Persist Security Info=True;User ID='+trim(FieldByName('loadid').AsString)+';Initial Catalog=master'+
';Data Source='+trim(FieldByName('ip').AsString)+';pooling=false';
Thrd.Create(false,v_dbstr);
next;
end;
end;
end;
错误提示 ....THread Error :句柄无效(6)....
哪位大侠能帮我改改吗
这几天为此事快憋疯了!
我是在一窗体的主程序中建立的线程,测试数据连结用的是adoconnection
Thrd = class(TThread)
private
{ Private declarations }
FDBInfo: string;
procedure UpdateUI;
protected
procedure Execute;
override;
public
constructor Create(Suspended: Boolean;
DBInfo: string);
end;
var
f_ljqk: Tf_ljqk;
implementation
{$R *.dfm}
constructor Thrd.Create(Suspended: Boolean;
DBInfo: string);
begin
FDBInfo := DBInfo;
end;
procedure Thrd.Execute;
var
ADO: TADOConnection;
begin
//self.FreeOnTerminate:=true;
ADO := TADOConnection.Create(nil);
ADO.Connectionstring := FDBInfo;
ado.CommandTimeout:=10;
ado.ConnectionTimeout:=5;
if ADO.connected then
Synchronize(UpdateUI)
{ Place thread code here }
end;
procedure Thrd.UpdateUI;
begin
//f_ljqk.label1.caption := '数库1成功';
showmessage('数库成功');
end;
procedure Tf_ljqk.FormCreate(Sender: TObject);
var
inifile: TIniFile;
v_Path,dbconstr,v_dbstr: string;
begin
with adoquery1do
begin
while not eofdo
begin
v_dbstr:='Provider=SQLOLEDB.1;Password='+trim(FieldByName('loadpwd').AsString)+';'+
'Persist Security Info=True;User ID='+trim(FieldByName('loadid').AsString)+';Initial Catalog=master'+
';Data Source='+trim(FieldByName('ip').AsString)+';pooling=false';
Thrd.Create(false,v_dbstr);
next;
end;
end;
end;
错误提示 ....THread Error :句柄无效(6)....
哪位大侠能帮我改改吗