Page 1 of 1

crash on mysql stop

Posted: Tue 25 Sep 2018 14:17
by roozgar
hello
i have a code to run every 2 seconds and it working in a background thread like this:

Code: Select all

    while not Terminated do
    begin
      FTermEvent.WaitFor(2000);
      if not Terminated then
      begin
          try
            UniConnectionRead := TUniConnection.Create(nil);
            UniConnectionRead.ProviderName:='Mysql';
            UniConnectionRead.Server := globalDBIP;
            UniConnectionRead.Username := globalDBUn;
            UniConnectionRead.Password := globalDBPass;
            UniConnectionRead.Database := globalDBName;
            UniConnectionRead.AutoCommit := true;
            UniConnectionRead.SpecificOptions.Values['MySQL.UseUnicode'] := 'True';
            UniConnectionRead.Connected := true;

            UniQueryRead := tuniquery.Create(nil);
            UniQueryRead.Connection := UniConnectionRead;

		//my process


          finally
            UniQueryRead.Close;
            UniQueryRead.Free;
            UniConnectionRead.Close;
            UniConnectionRead.Free;
          end;

	end;
      end;
when i turn off and turn on database server the loop dont work any more
what is the problem !?

Re: crash on mysql stop

Posted: Wed 26 Sep 2018 14:08
by ViktorV
This behavior does not apply to the UniDAC functionality, but rather to the development of multi-threaded applications. As stated in the Embarcadero documentation - https://docwiki.embarcadero.com/RADStud ... d_Function: With a TThread object, if you do not catch an exception in the Execute procedure of a TThread, you may get access violations. The Delphi IDE may break fine on the exception, but often when the application is running out of the IDE you can get an "Application error has occurred".
You can check this by changing your example so that our components are not used and any error is released.
To solve your problem, you should use the try..except construct.

Re: crash on mysql stop

Posted: Thu 27 Sep 2018 06:28
by roozgar
so i changed my code like this

Code: Select all

        try
          try
              //Set read connection
              UniConnectionRead := TUniConnection.Create(nil);
              UniConnectionRead.ProviderName:='Mysql';
              UniConnectionRead.Server := globalDBIP;
              UniConnectionRead.Username := globalDBUn;
              UniConnectionRead.Password := globalDBPass;
              UniConnectionRead.Database := globalDBName;
              UniConnectionRead.AutoCommit := true;
              UniConnectionRead.SpecificOptions.Values['MySQL.UseUnicode'] := 'True';
              UniConnectionRead.Connected := true;

              UniQueryRead := tuniquery.Create(nil);
              UniQueryRead.Connection := UniConnectionRead;
              UniQueryRead.SQL.Text := 'SELECT'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=857 order by tmfdid DESC limit 1) AS ye,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=1310 order by tmfdid DESC limit 1) AS mo,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=1311 order by tmfdid DESC limit 1) AS da,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=858 order by tmfdid DESC limit 1) AS ha,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=1312 order by tmfdid DESC limit 1) AS mi,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=1313 order by tmfdid DESC limit 1) AS se,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=859 order by tmfdid DESC limit 1) AS x,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=860 order by tmfdid DESC limit 1) AS y,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=861 order by tmfdid DESC limit 1) AS z,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=862 order by tmfdid DESC limit 1) AS vx,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=863 order by tmfdid DESC limit 1) AS vy,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=864 order by tmfdid DESC limit 1) AS vz;';

              UniQueryRead.Active := true;
              UniQueryRead.Open;
              TThread.Synchronize (TThread.CurrentThread,
              procedure ()
              begin
                form2.memo9.Lines.Add( UniQueryRead.FieldByName('ye').AsString +':'+

                                        UniQueryRead.FieldByName('vx').AsString +':'+
                                        UniQueryRead.FieldByName('vy').AsString +':' +
                                        UniQueryRead.FieldByName('vz').AsString );
              end);
          except
            on E : Exception do form2.memo9.Lines.Add(E.ClassName+' , message: '+E.Message);
          end;
        finally
          UniQueryRead.Close;
          UniQueryRead.Free;
          UniConnectionRead.Close;
          UniConnectionRead.Free;
        end;
but when i stop mysql server i got this error:

Code: Select all

EUniError , message: Cannot connect to server on host '192.168.30.139':
No connection could be made because the target machine actively refused it.
Socket Error Code: 10061($274D)
but after start mysql again it dont start working!!
is there any thing wrong ?!

Re: crash on mysql stop

Posted: Thu 27 Sep 2018 10:37
by ViktorV
To solve your issue you can use next code:

Code: Select all

        try
          UniConnectionRead := TUniConnection.Create(nil);
          try
            UniConnectionRead.ProviderName:='Mysql';
            UniConnectionRead.Server := globalDBIP;
            UniConnectionRead.Username := globalDBUn;
            UniConnectionRead.Password := globalDBPass;
            UniConnectionRead.Database := lobalDBName;
            UniConnectionRead.AutoCommit := true;
            UniConnectionRead.SpecificOptions.Values['MySQL.UseUnicode'] := 'True';
            UniConnectionRead.Connected := true;
            UniQueryRead := TUniQuery.Create(nil);
            try
              UniQueryRead.Connection := UniConnectionRead;
              UniQueryRead.SQL.Text := 'SELECT'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=857 order by tmfdid DESC limit 1) AS ye,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=1310 order by tmfdid DESC limit 1) AS mo,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=1311 order by tmfdid DESC limit 1) AS da,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=858 order by tmfdid DESC limit 1) AS ha,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=1312 order by tmfdid DESC limit 1) AS mi,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=1313 order by tmfdid DESC limit 1) AS se,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=859 order by tmfdid DESC limit 1) AS x,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=860 order by tmfdid DESC limit 1) AS y,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=861 order by tmfdid DESC limit 1) AS z,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=862 order by tmfdid DESC limit 1) AS vx,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=863 order by tmfdid DESC limit 1) AS vy,'+
                                        '(SELECT `value` FROM tm_frame_data_val where frame_data_id=864 order by tmfdid DESC limit 1) AS vz;';
              UniQueryRead.Open;
              TThread.Synchronize (TThread.CurrentThread,
              procedure ()
              begin
                form2.memo9.Lines.Add( UniQueryRead.FieldByName('ye').AsString +':'+

                                        UniQueryRead.FieldByName('vx').AsString +':'+
                                        UniQueryRead.FieldByName('vy').AsString +':' +
                                        UniQueryRead.FieldByName('vz').AsString );
              end);
            finally
              UniQueryRead.Free;
            end;
          finally
            UniConnectionRead.Free;
          end;
        except
          on E : Exception do form2.memo9.Lines.Add(E.ClassName+' , message: '+E.Message);
        end;

Re: crash on mysql stop

Posted: Sat 29 Sep 2018 12:47
by roozgar
Thank you , my problem resolved :)
but i dont understand why you used two separated
"try / finally" for TUniConnection.Create(nil); and the rest part of code ?1

is this helpful for my project ?!

Re: crash on mysql stop

Posted: Mon 01 Oct 2018 11:20
by ViktorV
We provided one variant of solving the problem. This variant is not the only one. You can get more information about using the Try-Finally phrase in the Embarcadero documentation or in their blog: https://community.embarcadero.com/blogs ... -in-delphi

Re: crash on mysql stop

Posted: Mon 01 Oct 2018 22:07
by smith987
I have launched MySQL in my new HP Spectre x360 laptop it was work properly for a few days but suddenly it stopped and not working I thought that it may be the device issue but after consulting with hp Canada I got to know that there is no any fault in the device it is the application error. Kindly suggest me the way.

Re: crash on mysql stop

Posted: Tue 02 Oct 2018 11:21
by ViktorV
If we are talking about MySQL server, then please address to MySQL Server technical support with your issue. If we are talking about our components, please provide more information.

Re: crash on mysql stop

Posted: Thu 25 Oct 2018 09:02
by anusinga
Hey! if this types of error face just close your application, if "Esc" button work then escape nor soft-boot your system "Ctrl+Alt+Delete" then go to task-bar close a particular application. Finally again open your SQL editor then edit you code.
I think you have some mistake in your SQL code, you start "infinite loop" so this types of error generate.

Re: crash on mysql stop

Posted: Thu 25 Oct 2018 10:15
by ViktorV
Thank you for the interest to our product.
Feel free to contact us if you have any further questions about our products.