以下是我在db(mysql)中检查数据的一些代码 创建......
CheckThread := TCheckThread.Create(True);
CheckThread.Start;
{TCheckThread}
procedure TCheckThread.Execute;
function AddLine(ALine: string): String;
begin
CsMemo.Enter;
Form1.Memo1.Lines.Add('[' + TimeToStr(Now) + ']SQL Checker ' + ALine);
CsMemo.Leave;
end;
var
DateCheckCount: integer;
begin
GDateCounter := 0;
FQry := TSQLQuery.Create(nil);
FSQLConnection := TSQLConnection.Create(nil);
try
FSQLConnection.DriverName := 'MySQL';
FSQLConnection.GetDriverFunc := 'getSQLDriverMYSQL';
FSQLConnection.LibraryName := 'dbxmys.dll';
FSQLConnection.VendorLib := 'libmysql.dll';
FSQLConnection.LoginPrompt := FAlse;
FSQLConnection.Params.Values['CharacterSet'] := 'utf8';
FSQLConnection.Params.Values['Names'] := 'utf8';
FSQLConnection.Params.Values['ServerCharSet'] := 'utf8';
FSQLConnection.Params.Values['Database'] := dbName;
FSQLConnection.Params.Values['User_Name'] := dbUser;
FSQLConnection.Params.Values['Password'] := dbPass;
FSQLConnection.Params.Values['HostName'] := dbHost;
FQry.SQLConnection := FSQLConnection;
while not self.Terminated do
begin
try
inc(DateCheckCount);
Foundmini := FAlse;
FQry.SQL.Text := 'SELECT * FROM `' + GlobTableVar + '` WHERE `state`=''Free''';;
FQry.Prepared := True;
FQry.Open();
while not FQry.Eof do
begin
GDateFound := True;
Foundmini := True;
AddLine('YE');
Break;
end;
FQry.Close;
if not Foundmini then
begin
GDateFound := FAlse;
AddLine('Check..')
end;
try
if random(6) = 1 then
Form1.LabelCheckDate.Caption := 'Check #' + inttostr(DateCheckCount);
except
end;
sleep(100);
except
on e: Exception do
begin
AddLine('[<< REQUEST THREAD DEBUG >>] ' + e.ClassName + ' EwM ' + e.Message);
FSQLConnection.Close;
FSQLConnection.Open;
end;
end;
end;
finally
FSQLConnection.Free;
FQry.Free;
end;
end;
当我的带有db的VPS重新启动(或关闭)时,我应该处理exeptions并尝试重新连接并再次检查数据。但是我的软件崩溃了(这个函数在Thread中使用)。
version : 1.0.0.0
compiled with : Delphi XE4
madExcept version : 4.0.9
callstack crc : $5bee8bf0, $af8b0065, $7eedcaab
exception number : 1
exception class : TDBXError
exception message : Can't connect to MySQL server on '82.146.40.149' (10061).
这是调用堆栈
thread $57b0 (TCheckThread):
00967d8d +051 VladSoft.exe Data.DBXCommon 10946 +8 TDBXContext.Error
00a14aa2 +10a VladSoft.exe Data.DBXDynalink 824 +21 TDBXMethodTable.RaiseError
00a150fb +013 VladSoft.exe Data.DBXDynalink 974 +1 TDBXDynalinkConnection.CheckResult
00a152ec +050 VladSoft.exe Data.DBXDynalink 1062 +4 TDBXDynalinkConnection.DerivedOpen
009638b7 +00b VladSoft.exe Data.DBXCommon 8510 +5 TDBXConnection.Open
0095ed36 +0fe VladSoft.exe Data.DBXCommon 6671 +14 TDBXConnectionFactory.GetConnection
0095ec31 +005 VladSoft.exe Data.DBXCommon 6648 +0 TDBXConnectionFactory.GetConnection
009f85fb +293 VladSoft.exe Data.SqlExpr 2487 +53 TSQLConnection.DoConnect
008f01ed +039 VladSoft.exe Data.DB 3483 +8 TCustomConnection.SetConnected
009f9630 +130 VladSoft.exe Data.SqlExpr 2870 +32 TSQLConnection.CloneConnection
00a041eb +07b VladSoft.exe Data.SqlExpr 6030 +7 TCustomSQLDataSet.CheckStatement
00a086ca +0a6 VladSoft.exe Data.SqlExpr 7550 +10 TSQLQuery.PrepareStatement
00a04082 +0fe VladSoft.exe Data.SqlExpr 5992 +45 TCustomSQLDataSet.SetPrepared
00a45b08 +1b8 VladSoft.exe Unit1 1385 +28 TCheckThread.Execute
004a9c43 +02b VladSoft.exe madExcept HookedTThreadExecute
0053d282 +042 VladSoft.exe System.Classes 14548 +12 ThreadProc
0040aad0 +028 VladSoft.exe System 22016 +45 ThreadWrapper
004a9b29 +00d VladSoft.exe madExcept CallThreadProcSafe
004a9b8e +032 VladSoft.exe madExcept ThreadExceptFrame
77443368 +010 kernel32.dll BaseThreadInitThunk
>> created by main thread ($51d4) at:
00a45036 +582 VladSoft.exe Unit1 1193 +48 TForm1.ButtonStartClick
thread $57b0 (TCheckThread), inner exception level 1:
>> TDBXError, Can't connect to MySQL server on '82.146.40.149' (10061)
00967d8d +051 VladSoft.exe Data.DBXCommon 10946 +8 TDBXContext.Error
00a14aa2 +10a VladSoft.exe Data.DBXDynalink 824 +21 TDBXMethodTable.RaiseError
00a150fb +013 VladSoft.exe Data.DBXDynalink 974 +1 TDBXDynalinkConnection.CheckResult
00a152ec +050 VladSoft.exe Data.DBXDynalink 1062 +4 TDBXDynalinkConnection.DerivedOpen
009638b7 +00b VladSoft.exe Data.DBXCommon 8510 +5 TDBXConnection.Open
0095ed36 +0fe VladSoft.exe Data.DBXCommon 6671 +14 TDBXConnectionFactory.GetConnection
0095ec31 +005 VladSoft.exe Data.DBXCommon 6648 +0 TDBXConnectionFactory.GetConnection
009f85fb +293 VladSoft.exe Data.SqlExpr 2487 +53 TSQLConnection.DoConnect
008f01ed +039 VladSoft.exe Data.DB 3483 +8 TCustomConnection.SetConnected
009f9630 +130 VladSoft.exe Data.SqlExpr 2870 +32 TSQLConnection.CloneConnection
00a041eb +07b VladSoft.exe Data.SqlExpr 6030 +7 TCustomSQLDataSet.CheckStatement
00a086ca +0a6 VladSoft.exe Data.SqlExpr 7550 +10 TSQLQuery.PrepareStatement
00a04082 +0fe VladSoft.exe Data.SqlExpr 5992 +45 TCustomSQLDataSet.SetPrepared
00a45b08 +1b8 VladSoft.exe Unit1 1385 +28 TCheckThread.Execute
0053d282 +042 VladSoft.exe System.Classes 14548 +12 ThreadProc
0040aad0 +028 VladSoft.exe System 22016 +45 ThreadWrapper
004a9b29 +00d VladSoft.exe madExcept CallThreadProcSafe
004a9b8e +032 VladSoft.exe madExcept ThreadExceptFrame
77443368 +010 kernel32.dll BaseThreadInitThunk
00a45036 +582 VladSoft.exe Unit1 1193 +48 TForm1.ButtonStartClick
有人能帮助我吗?我可以发送一些WebMoney来激励)