问题: ADOConnection断线重连问题
描述:
使用ADOConnection连接oracle数据库,开始正常,当网络断开时数据库连接失败(此时查询ADOConnection.connected属性是true),
用了 ADOConnection的query在open时都报错,想了一个解决方法,使用定时器判断如下:
var
adoq : TADOQuery; begin
adoq := TADOQuery.Create(nil);
adoq.Connection := dm.ADOConn;
adoq.Close;
adoq.SQL.Clear;
adoq.SQL.Add('select * from cat where 1=0');
try
adoq.Open;
except
try
dm.ADOConn.Connected := false;
dm.ADOConn.Connected := true;
except
end;
end;
end;
按理说应该重连上了,可是结果还是未连接状态。query在open时依然报错,请问怎么回事啊,怎样解决呢?
解决方案1:
var
adoq : TADOQuery;
begin
adoq := TADOQuery.Create(nil);
adoq.Connection := dm.ADOConn;
adoq.Close;
adoq.SQL.Clear;
adoq.SQL.Add('select * from cat where 1=0');
try
try
if dm.ADOConn.Connected then
dm.ADOConn.Connected := false; dm.ADOConn.Connected := true;
except
end;
adoq.Open;
except
end;
end;
解决方案2:
var
adoq : TADOQuery; begin
adoq := TADOQuery.Create(nil);
adoq.Connection := dm.ADOConn;
adoq.Close;
adoq.SQL.Clear;
adoq.SQL.Add('select * from cat where 1=0'); try
try
dm.ADOConn.Connected := false;
dm.ADOConn.Connected := true;
except
end;
adoq.Open;
except
end;
end;
以上介绍了“ ADOConnection断线重连问题”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3187629.html