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.
UniConnectDialog1 : Hitting 'cancel' hangs the application
Re: UniConnectDialog1 : Hitting 'cancel' hangs the application
Did this :
But the Logindialog keeps popping back...
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;
Re: UniConnectDialog1 : Hitting 'cancel' hangs the application
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:
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;
Re: UniConnectDialog1 : Hitting 'cancel' hangs the application
Problem is that when you call :
It hangs the application ! ? ?
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;
Re: UniConnectDialog1 : Hitting 'cancel' hangs the application
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 ?
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 ?
Re: UniConnectDialog1 : Hitting 'cancel' hangs the application
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:
More information about TUniConnectDialog.Execute:
https://www.devart.com/unidac/docs/?dev ... cute().htm
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;
https://www.devart.com/unidac/docs/?dev ... cute().htm