Retrieving error codes from SQLite when using Exec

2020-02-06 16:40发布

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.

3条回答
三岁会撩人
2楼-- · 2020-02-06 17:14

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
}
查看更多
Juvenile、少年°
3楼-- · 2020-02-06 17:32

use the Exception.StackTrace or the SQLiteException.ErrorCode

try
{

}
catch(SQLiteException ex)
{
    string code = ex.ErrorCode;
}
查看更多
Ridiculous、
4楼-- · 2020-02-06 17:36

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

    Catch Ex As SQLiteException
        E = Ex.ResultCode
        Return E
    End Try
查看更多
登录 后发表回答