I am using Microsoft.Data.Sqlite.Core
(9.0.2) together with SQLitePCLRaw.bundle_e_sqlcipher
and I am getting issues with SqliteCommand
when I have created an active transaction on the connection. The error says I need to set the Transaction
property on the command object.
However my understanding is the current version of Microsoft.Data.Sqlite.Core
does this automatically now.
According to this Microsoft documentation for the SqliteConnection
there should be a Transaction
property which I do not see. And I am definitely using the latest Microsoft.Data.Sqlite.Core
from nuget.
What am I missing?
I am using Microsoft.Data.Sqlite.Core
(9.0.2) together with SQLitePCLRaw.bundle_e_sqlcipher
and I am getting issues with SqliteCommand
when I have created an active transaction on the connection. The error says I need to set the Transaction
property on the command object.
However my understanding is the current version of Microsoft.Data.Sqlite.Core
does this automatically now.
According to this Microsoft documentation for the SqliteConnection
there should be a Transaction
property which I do not see. And I am definitely using the latest Microsoft.Data.Sqlite.Core
from nuget.
What am I missing?
Share Improve this question edited Mar 12 at 3:09 Brando Zhang 28.7k6 gold badges42 silver badges70 bronze badges asked Mar 10 at 18:18 Michael TMichael T 7918 silver badges23 bronze badges 3 |1 Answer
Reset to default 1The document said clearly, the Transaction is the internal usage which means you couldn't use it directly.
protected internal virtual Microsoft.Data.Sqlite.SqliteTransaction? Transaction { get; set; }
So if you want to use Transaction , I suggest you could follow below codes:
// Open a connection
using var connection = new SqliteConnection("Data Source=your_database.db;Password=your_password");
connection.Open();
// Begin a transaction
using var transaction = connection.BeginTransaction();
using var command = connection.CreateCommand();
command.Transaction = transaction;
command.CommandText = "INSERT INTO YourTable (Column1) VALUES ('Value1')";
// Execute the command
command.ExecuteNonQuery();
// Commit the transaction
transaction.Commit();
SqliteConnection
has thatTransaction
property asprotected internal
. – pfx Commented Mar 10 at 18:54