Page 1 of 1

Delphi XE7 SDAC Table Locking

Posted: Mon 08 Dec 2014 03:41
by bryn.ball
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?

Re: Delphi XE7 SDAC Table Locking

Posted: Wed 10 Dec 2014 11:29
by azyk
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;