Error handling and rollback transaction in SQLITE from SQL query

I am modifying several sqlite tables with an SQL script by calling ExecuteNonQuery . I want to perform this operation in a transaction, and I want to discard it when something fails.

I looked at BEGIN TRANSACTIONand it is clear that I need to call ROLLBACK TRANSACTIONwhen something goes wrong. But I do not know how TRY ... CATCH (Transact-SQL) is here.

NOTE. The entire Sql script file (which contains many other statements, in addition to these several statements that must be run in the same transaction) is read using .ReadToEnd () and then executed at a time. I want to handle this in a sql script file and don't want to change the code.

+3
source share
1

, SQLite on conflict

BEGIN TRANSACTION

ON CONFLICT ROLLBACK

COMMIT TRANSACTION ; -)

+4

All Articles