Delphi XE7 SDAC Table Locking

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
bryn.ball
Posts: 1
Joined: Mon 08 Dec 2014 03:32

Delphi XE7 SDAC Table Locking

Post by bryn.ball » Mon 08 Dec 2014 03:41

I am new to SDAC and SQL Server.

The option to lock a table for bulk update is very useful.
When another instance of my application tries to open the table, how can I detect that the table has a lock placed on it by another user before calling Open.

Calling open and displaying the lock timeout error message seems messy. Delphi only hands back an standard Exception so there are no error codes to analyse which means I would have to detect that the string contained the lock timeout message.

Is there a better way?

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

Re: Delphi XE7 SDAC Table Locking

Post by azyk » Wed 10 Dec 2014 11:29

You can handle this error ( http://www.microsoft.com/technet/suppor ... SSQLServer ) by the error code in a try ... except block using EMSError exceptions. The error code value is stored in the EMSError.MSSQLErrorCode property. For example:

Code: Select all

  try
    MSQuery.Open;
  except
    on E:EMSError do
    begin
      if E.MSSQLErrorCode = 1222 then
      // DoSomething;
      ...
    end;
  end;

Post Reply