I have the following problem qith my local SQLite database. I'm trying to update the data stored via a synchronisation-process with an online SQL-Server database. While there is no problem with the synchonization I often encounter errors when trying to update the local values. E.g. there can be an violation with existing Primary-Key-Constraints on each table. On the other hand there could also be a violation of the Unique-Key on a concrete table.
My question is how to figure out which type of error occured.
I catch the database update or insert like
catch(UpdateException ue)
{
HandleUpdateException(ue);
}
The handle method is as follows:
private void HandleUpdateException(UpdateException e)
{
// get inner exception as SQLiteException
var innerException = e.InnerException as SQLiteException;
if(innerException != null)
{
switch(innerException.ErrorCode)
{
case SQLiteError.Constraint:
// handle constraint-error here
break;
default:
// log error
break;
}
}
}
How do I now which error occured? It's important to know because the handling of PK-violation is completely other than a UK-violation.
I could try to make
if(e.Message.Contains("unique")) // ...
or
if(e.Message.Contains("foreign")) // ...
but I don't like to check with "magic" strings for the kind of error.
So any help would be appreciated.