Dealing with connection errors

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
xxxFALKORxxx
Posts: 4
Joined: Fri 20 Jul 2018 17:42

Dealing with connection errors

Post by xxxFALKORxxx » Fri 20 Jul 2018 17:45

Hi;

is there any piece of code where i can see how to deal with exceptions when i try to connect to server?

im using Delphi 7

TIA

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

Re: Dealing with connection errors

Post by ViktorV » Mon 23 Jul 2018 08:23

To solve your task, you can use the EMyError.ErrorCode property of https://devart.com/mydac/docs/devart.da ... orcode.htm. You can find more information about the possible values of this property in MySQL server documentation: https://dev.mysql.com/doc/refman/5.5/en ... erver.html and https://dev.mysql.com/doc/refman/5.5/en ... lient.html

Code: Select all

try
  MyConnection1.Connect;
except
  on E: EMyError do
    if EMyError(E).ErrorCode = 1045 then
      ShowMessage('Access denied for user: ' + MyConnection1.Username)
    else
      raise;
end;
Note that to run this code, you should add the MyClasses unit to the USES clause of your unit.

Post Reply