Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
			
		
		
			- 
				
																			 roozgar
- Posts: 12
- Joined: Thu  24 May 2018 13:05
						
						
													
							
						
									
						Post
					
								by roozgar » Tue  25 Sep 2018 14:17
			
			
			
			
			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 !?
 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			 ViktorV
- Devart Team
- Posts: 3168
- Joined: Wed  30 Jul 2014 07:16
						
						
													
							
						
									
						Post
					
								by ViktorV » Wed  26 Sep 2018 14:08
			
			
			
			
			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.
 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			 roozgar
- Posts: 12
- Joined: Thu  24 May 2018 13:05
						
						
													
							
						
									
						Post
					
								by roozgar » Thu  27 Sep 2018 06:28
			
			
			
			
			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 ?!
 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			 ViktorV
- Devart Team
- Posts: 3168
- Joined: Wed  30 Jul 2014 07:16
						
						
													
							
						
									
						Post
					
								by ViktorV » Thu  27 Sep 2018 10:37
			
			
			
			
			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;
 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			 roozgar
- Posts: 12
- Joined: Thu  24 May 2018 13:05
						
						
													
							
						
									
						Post
					
								by roozgar » Sat  29 Sep 2018 12:47
			
			
			
			
			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 ?!
			
									
									
						 
		 
				
		
		 
	 
	
				
	
				
		
		
			- 
				
																			 smith987
- Posts: 1
- Joined: Mon  01 Oct 2018 21:56
						
						
													
							
						
									
						Post
					
								by smith987 » Mon  01 Oct 2018 22:07
			
			
			
			
			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.
 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			 ViktorV
- Devart Team
- Posts: 3168
- Joined: Wed  30 Jul 2014 07:16
						
						
													
							
						
									
						Post
					
								by ViktorV » Tue  02 Oct 2018 11:21
			
			
			
			
			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.
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			 anusinga
- Posts: 1
- Joined: Thu  25 Oct 2018 08:54
- Location: Dallas, TX, USA
- 
				Contact:
				
			
						
						
													
							
						
									
						Post
					
								by anusinga » Thu  25 Oct 2018 09:02
			
			
			
			
			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.
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			 ViktorV
- Devart Team
- Posts: 3168
- Joined: Wed  30 Jul 2014 07:16
						
						
													
							
						
									
						Post
					
								by ViktorV » Thu  25 Oct 2018 10:15
			
			
			
			
			Thank you for the interest to our product.
Feel free to contact us if you have any further questions about our products.