Mysql Connect in Delphi. Error handling in TDBX (dbExpress) -
here code how check data in db ( mysql) creating ...
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 begin try inc(datecheckcount); foundmini := false; fqry.sql.text := 'select * `' + globtablevar + '` `state`=''free''';; fqry.prepared := true; fqry.open(); while not fqry.eof begin gdatefound := true; foundmini := true; addline('ye'); break; end; fqry.close; if not foundmini begin gdatefound := false; addline('check..') end; try if random(6) = 1 form1.labelcheckdate.caption := 'check #' + inttostr(datecheckcount); except end; sleep(100); except on e: exception begin addline('[<< request thread debug >>] ' + e.classname + ' ewm ' + e.message); fsqlconnection.close; fsqlconnection.open; end; end; end; fsqlconnection.free; fqry.free; end; end;
when vps db going reboot ( or down) should hande exeptions , try reconnect , check data again. software crashing ( function used in thread).
version : 1.0.0.0 compiled : delphi xe4 madexcept version : 4.0.9 callstack crc : $5bee8bf0, $af8b0065, $7eedcaab exception number : 1 exception class : tdbxerror exception message : can't connect mysql server on '82.146.40.149' (10061).
here call stack
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 main thread ($51d4) at: 00a45036 +582 vladsoft.exe unit1 1193 +48 tform1.buttonstartclick thread $57b0 (tcheckthread), inner exception level 1: >> tdbxerror, can't connect 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
can me? can send webmoney motivate )
Comments
Post a Comment