Dear Gaxm:
非常感謝你的熱心幫助!
補充: 該問題是在 系統運行了近5小時 左右 才報出來的.
連接代碼如下:
代碼1:
var RLConnectStr,BKConnectStr : WideString;
localPcName,sqlstr: string;
R1,R2,R3,R4,R5,R6: Boolean;
para : variant;
idx : integer;
Function AdoConnectToSqlServer(ConnectStr:wideString; var ADOConnection: TADOConnection): boolean;
begin
Result := false;
with ADOConnection do begin
if Connected then begin
Result := true;
exit;
end;
ConnectionString := ConnectStr;
Connected :=true;
end;
Result :=true;
end;
begin
isBtnOk:=true;
Usr := 'tradm'; //UpperCase(LbledtUser.Text);
Pwd := 'tradm'; //UpperCase(LbledtPassword.Text);
DBName :='trupload'; // UpperCase(LabeledEdit1.Text);
RLPcName :='191.191.22.155'; // UpperCase(LblEdtServerID.Text);
BKPcName :='191.191.22.155'; // UpperCase(LabeledEdit2.Text);
localPcName :=GetLocalIp; // GetLocalPcName;
//1. 連接實時數據庫
if uppercase(trim(RLPcName)) = uppercase(trim(localPcName)) then // 本地數據庫
RLconnectstr:='Provider=SQLOLEDB.1;Persist Security Info=False;' +
'Initial Catalog='+ DBName + ';' +
'User ID=' + Usr + ';' +
'Password=' + Pwd + ';' +
'Data Source=(local)'
else // 遠端數據庫
RLconnectstr:='Provider=SQLOLEDB.1;Persist Security Info=False;' +
'Initial Catalog='+ DBName + ';' +
'User ID=' + Usr + ';' +
'Password=' + Pwd + ';' +
'Data Source=' + RLPcName ;
//RLconnectstr:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=StoreCard.mdb;Persist Security Info=False';
//Provider=SQLOLEDB;Persist Security Info=False;User ID=tradm;Initial Catalog=trUpLoad;Data Source=191.191.22.155
//2. 連接備份數據庫
try
R1:=false; R2:=false; R3:=false; R4:=False; R5:=False;
R1 := AdoConnectToSqlServer(RLconnectStr,DmF.ADOConnection1);
R2 := AdoConnectToSqlServer(RLconnectStr,DmF.ADOConnection2);
except
end;
代碼2:
function GetLocalIp: string;
type
TapInAddr = array [0..10] of pinAddr;
papinaddr = ^Tapinaddr;
var
phe : PhostEnt;
pptr : PapInAddr;
Buffer : array [0..63] of char;
I : integer;
GInitData : Twsadata;
begin
wsaStartUp($101,GInitData); //打開WinSock
Result := '';
fillchar(buffer,high(buffer)+1,0);
GetHostName(Buffer,sizeof(buffer));
phe := GetHostByname(buffer);
if phe=nil then exit;
pptr := papInaddr(phe^.h_addr_list);
i:=0;
while pptr^<>nil do begin
result := strpas(Inet_Ntoa(pptr^^));
inc(i);
end;
wsacleanup; //關閉WinSock
end;
代碼3: (就是在此過程中發生的錯誤)
Function QryBKRecByQuery(ParaV:Variant; sqlStr:string; Qry:TAdoQuery; Flag:integer; var ADOConnection: TADOConnection):LongInt;
var i: integer;
ErrCode,ReCnt:integer;
ErrStr: string;
isgoto: boolean;
usr,pwd,DBName,RLPcName,BkPcName : string;
label Re;
begin
ReCnt :=0;
if not ADOConnection.Connected then begin
LoadLogInfo(usr,pwd,DBName,RLPcName,BkPcName);
if not RestartConnectDB(usr,pwd,DBName,BKPcName,ADOConnection) then begin
Result:=-2;
Exit;
end;
end;
Re:
isgoto := false;
inc(ReCnt);
try
with Qry do begin
close;
Sql.Clear ;
sql.Add(sqlStr); //自動創建參數
For i:=0 to Parameters.Count-1 do
Parameters.Value :=parav;
if Flag =0 then begin
open;
Result := RecordCount
end else begin
ExecSQL ;
result :=-1;
end;
end;
Except on E:Exception do begin
ErrCode := e.HelpContext;
ErrStr := E.Message;
if ((Errcode=0) and (pos('不存在',Errstr)>0)) or (trim(ErrStr)=trim('連線失敗')) then begin
LoadLogInfo(usr,pwd,DBName,RLPcName,BkPcName);
ADOConnection.Connected := false;
if RestartConnectDB(usr,pwd,DBName,BKPcName,ADOConnection) then isgoto:=true;
end else begin
Result:=-2;
Qry.Close ;
end;
end;
end;
if isgoto and (ReCnt<=3) then goto Re;
end;
代碼顯示完畢.