Page 1 of 1

MyDAC - Connection - OnError

Posted: Wed 02 Jan 2008 23:09
by naumov13
Hello!
I am sorry for my English :)
I have the next problem with OnError event at TMyConnection.

procedure TmyDataModule.MySQLConnectionError(Sender: TObject; E: EDAError; var Fail: Boolean);
begin

unit2.myDataModule.MySQLConnection.Disconnect;
// i don't know is that command necessary, but i use it to make secure

Fail:= false;
// it used don't display error message

unit3.ParamForm.ShowModal;
// show form where user can change connection parameters
// and try to connect again

end;

My problem at last command. when user change parameters and successful connecting with mysql server, then unit3.ParamForm is closed. that is all right.
But, independently of fact, was the command "Disconnect" used by me or not, Disconnect is occurs after OnError event is finished. Thus, the actions executed by the user (try to connect), was useless.

Whether, can I make so that Disconnect did not occur automatically after OnError event is finished? Or I have to use ParamForm at another procedure after OnError event?

Thank You!

Posted: Thu 03 Jan 2008 10:16
by Dimon
In your case you do not need to handle the OnError event.
If an error arises on an open connection, then TMyConnection will do reconnect by itself. If the error arises on connecting, use the TMyConnectDialog component, or use the following code:

Code: Select all

try
  unit2.myDataModule.MySQLConnection.Connect;
except
  on E: EMyError do
  unit3.ParamForm.ShowModal;
end;

Posted: Thu 03 Jan 2008 11:38
by naumov13
Dimon wrote:In your case you do not need to handle the OnError event. If an error arises on an open connection, then TMyConnection will do reconnect by itself. If the error arises on connecting, use the TMyConnectDialog component, or use the following code.
Thanks for your reply.
If the error arises on connecting, I'm using code, similar that you wrote. That is all right.
But if an error arises on an open connection, I need not TMyConnection do reconnect by itself. I want, that the user himself could solve, what to do.

Posted: Thu 03 Jan 2008 15:33
by Dimon
You can call TMyConnection.Disconnect, but not TMyConnection.Connect in the OnError event handler. Connection parameters can be changed when a connection is necessary. For this you should handle the TMyConnection.BeforeConnect event.

Posted: Sat 05 Jan 2008 21:58
by naumov13
Thanks, I have understood! :wink:

Re: MyDAC - Connection - OnError

Posted: Sun 13 May 2018 12:29
by marsheng
I'm too am trying to see if I can establish a valid connection.

Do I need to add something to my uses line, I get an error on EMyError, Undeclared identifier.

Re: MyDAC - Connection - OnError

Posted: Mon 14 May 2018 10:40
by ViktorV
The EMyError is defined in the MyClasses.pas module. To solve the issue related with the "Undeclared identifier error:", please add the MyClasses module to the uses section of your module.

Re: MyDAC - Connection - OnError

Posted: Mon 14 May 2018 20:42
by marsheng
Thanks, now compiles.

What I'm trying to do is to catch the error when trying to connect to the SQL. The user has 2 options for the SQL , Local or remote I need to catch the error If a user tries to login with the wrong source.

I'm not that clued up with the Debugger. I get

XX raised and exception class EMYSqlException with message
#xxx Access denied for user *****************

Code: Select all

procedure TfLogin.LoginClick(Sender: TObject);
begin
   dm.Regisiter.Username:= eName.Text;
   dm.Regisiter.Password:= ePassword.Text;
   try
      dm.Regisiter.connect;
      except
      on E: EMyError do
      showMessage('Not connected');
  end;
      
end;
General question - How do you find what module is required when you get unidentified identifier.?

Re: MyDAC - Connection - OnError

Posted: Tue 15 May 2018 07:03
by ViktorV
Please explain what you mean by the phrase "How do you find what module is required when you get unidentified identifier.?"

Re: MyDAC - Connection - OnError

Posted: Tue 15 May 2018 20:36
by marsheng
{quote]The EMyError is defined in the MyClasses.pas module.[/quote]

So if I get an error, how do I find out what to add to my uses list ? [

Re: MyDAC - Connection - OnError

Posted: Wed 16 May 2018 11:08
by ViktorV
You can use MyDAC help to determine in which module the required class is declared. For example: https://devart.com/mydac/docs/devart.mydac.emyerror.htm