Retrieving error codes from SQLite when using ExecuteNonQuery()
Asked Answered
B

3

2

In my C# project, I'm using System.Data.SQLite.dll downloaded from CodeProject.

My problem is as per the title - how to get the error codes after calling SqliteCommand.ExecuteNonQuery() function?

Error codes such as SQLITE_CONSTRAINT, SQLITE_BUSY, SQLITE_LOCKED as shown here.

Buckjumper answered 27/6, 2012 at 9:21 Comment(0)
S
4

use the Exception.StackTrace or the SQLiteException.ErrorCode

try
{

}
catch(SQLiteException ex)
{
    string code = ex.ErrorCode;
}
Strade answered 27/6, 2012 at 9:45 Comment(0)
T
1

I'm going to add to this to help others, if you're developing in .NET. Use the

SQLiteErrorCode enumeration to test the result, cast the ErrorCode:

try
{

}
catch(SQLiteException ex)
{
    SQLiteErrorCode sqlLiteError= (SQLiteErrorCode)ex.ErrorCode;

    //Do whatever logic necessary based of the error type
}
Telega answered 26/3, 2019 at 14:2 Comment(0)
K
0

Good question. System.Exception does not have a member by the name ".ErrorCode"

    Catch Ex As SQLiteException
        E = Ex.ResultCode
        Return E
    End Try
Kikuyu answered 26/10, 2013 at 3:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.