MyDAC - Connection - OnError

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
naumov13
Posts: 9
Joined: Wed 02 Jan 2008 22:44

MyDAC - Connection - OnError

Post by naumov13 » Wed 02 Jan 2008 23:09

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!

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 03 Jan 2008 10:16

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;

naumov13
Posts: 9
Joined: Wed 02 Jan 2008 22:44

Post by naumov13 » Thu 03 Jan 2008 11:38

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.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 03 Jan 2008 15:33

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.

naumov13
Posts: 9
Joined: Wed 02 Jan 2008 22:44

Post by naumov13 » Sat 05 Jan 2008 21:58

Thanks, I have understood! :wink:

marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Re: MyDAC - Connection - OnError

Post by marsheng » Sun 13 May 2018 12:29

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.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: MyDAC - Connection - OnError

Post by ViktorV » Mon 14 May 2018 10:40

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.

marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Re: MyDAC - Connection - OnError

Post by marsheng » Mon 14 May 2018 20:42

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.?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: MyDAC - Connection - OnError

Post by ViktorV » Tue 15 May 2018 07:03

Please explain what you mean by the phrase "How do you find what module is required when you get unidentified identifier.?"

marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Re: MyDAC - Connection - OnError

Post by marsheng » Tue 15 May 2018 20:36

{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 ? [

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: MyDAC - Connection - OnError

Post by ViktorV » Wed 16 May 2018 11:08

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

Post Reply