1

What is the best way, to catch a table lock exception with ado.net and iAnywhere.Data.SqlAnywhere.EF6? My problem is, that command.ExecuteNonQuery cause a SAException which contains the message, that a user has locked all rows in a table.

The problem is, that it is a general SAException, not a specific one like SATableLockException, which would be nice.

Now the question: how to detect without using the error message, that the error is a table lock exception?

Thank you very much!

BendEg
  • 20,098
  • 17
  • 57
  • 131
  • Looking at the SQL Anywhere 16 NET API reference I can't find a SATableLockException, therefore I'm not sure if it is possible to detect the error without looking at the SAError list of the Errors property of the SAException class. – tzup Aug 20 '15 at 09:31

1 Answers1

0

Ok, i found a solution for this. I just cast the exception to SAException and userd the Error-Code property (thank you @tzup):

Example:

try
{
    // Maybe some sa-exception occurse
}
catch (Exception ex)
{
    if (ex is iAnywhere.Data.SQLAnywhere.SAException)
    {
        var saException = (iAnywhere.Data.SQLAnywhere.SAException)ex;

        // Only catch table locks
        if (saException.NativeError == -210 || saException.ErrorCode == -210
             || saException.NativeError == -1281 || saException.ErrorCode == -1281)
        {
            // Table lock here!
        }
    }
    else { // do some thing else... }
}
BendEg
  • 20,098
  • 17
  • 57
  • 131