UniConnectDialog1 : Hitting 'cancel' hangs the application

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Senad
Posts: 34
Joined: Tue 10 Dec 2013 08:07

UniConnectDialog1 : Hitting 'cancel' hangs the application

Post by Senad » Mon 05 Dec 2016 06:51

This was asked before (with no adequate answer) so ... once more :
Unidac is 6.4.16 and IDE is Berlin 10.1 Aniversarry edition.

I am using UniConnectDialog1 to connect to SQL server. As a matter of fact, dropping the
UniConnectDialog1 on the form is futile because enabling the 'Login prompt' in the UniConnection1 triggers the UniConnectDialog1 anyway. So what is the point of the UniConnectDialog1?
Anyway, I like your connection dialog which is much better than the FireDAC one.
The issue is this :
If I do not supply the username in the UniConnectDialog1 and hit 'Cancel' the
application hangs (!?). I get the Exception (EDatabase error) : Cannot connect to database.

Your demos are not helping either.
So please enlighten me on what must I do to make the connection function normally and
where and how to catch these errors.

Senad
Posts: 34
Joined: Tue 10 Dec 2013 08:07

Re: UniConnectDialog1 : Hitting 'cancel' hangs the application

Post by Senad » Mon 05 Dec 2016 08:12

Did this :

Code: Select all

procedure TDataModule2.DataModuleCreate(Sender: TObject);
begin
UNIConnection1.ConnectDialog := UniConnectDialog1;
try
UniConnection1.Connect;
except
on E: Exception do
ShowMessage(E.ClassName+'Napaka pri povezavi : '+E.Message);
end;
end;
But the Logindialog keeps popping back...

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: UniConnectDialog1 : Hitting 'cancel' hangs the application

Post by azyk » Wed 07 Dec 2016 08:35

Among other things TUniConnectDialog allows to customize buttons and labels names in the connection dialog. For example, if you set the 'host\instance' value to the TUniConnectDialog.ServerLabel property, a user will see host\instance instead of standard Server in the dialogue. More details about TUniConnectDialog in our online documentation: https://www.devart.com/unidac/docs/?dev ... embers.htm

When clicking the Cancel button in TUniConnectDialog UniDAC calls the Abort method. You can handle the occurring error in the try ... except block using EAbort exceptions. For example, you can change the provided code this way:

Code: Select all

procedure TDataModule2.DataModuleCreate(Sender: TObject);
begin
UNIConnection1.ConnectDialog := UniConnectDialog1;
try
UniConnection1.Connect;
except
on E: EAbort do DoSomething ; 
on E: Exception do
ShowMessage(E.ClassName+'Napaka pri povezavi : '+E.Message);
end;
end;

Senad
Posts: 34
Joined: Tue 10 Dec 2013 08:07

Re: UniConnectDialog1 : Hitting 'cancel' hangs the application

Post by Senad » Thu 08 Dec 2016 04:58

Problem is that when you call :

Code: Select all

procedure TDataModule2.DataModuleCreate(Sender: TObject);
begin
UNIConnection1.ConnectDialog := UniConnectDialog1;
try
UniConnection1.Connect;
except
on E: EAbort do Application.Terminate;
on E: Exception do
ShowMessage(E.ClassName+'Napaka pri povezavi: '+E.Message);
end;
It hangs the application ! ? ?

Senad
Posts: 34
Joined: Tue 10 Dec 2013 08:07

Re: UniConnectDialog1 : Hitting 'cancel' hangs the application

Post by Senad » Thu 08 Dec 2016 12:08

I think there's a bug in your component.
Clicking cancel should abort the login attempt and close the application.
However it seems that your UniConnection1 is ignoring the UniConnectDialog1
and tries to connect anyway. That's why I am getting :

2.5 Type : EDatabaseError
2.6 Message: Cannot connect to database.

Because if the connection attempt was aborted, why the connection malfunction and thus the error ?

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: UniConnectDialog1 : Hitting 'cancel' hangs the application

Post by azyk » Fri 09 Dec 2016 09:53

To solve the problem use the call TUniConnection.ConnectDialog.Execute instead of TUniConnection.Connect. The Execute function result will be False if a user presses Cancel. For example:

Code: Select all

procedure TDataModule2.DataModuleCreate(Sender: TObject);
begin
UNIConnection1.ConnectDialog := UniConnectDialog1;
try
if not UniConnection1.ConnectDialog.Execute
then //user prees cancel
...
except
on E: Exception do
ShowMessage(E.ClassName+'Napaka pri povezavi : '+E.Message);
end;
end;
More information about TUniConnectDialog.Execute:
https://www.devart.com/unidac/docs/?dev ... cute().htm

Post Reply