Sqlite only supports one transaction?

When using ADO.NET (maybe I'm wrong, I don't know what it's called), I notice that I can only start a transaction with a connection, and the command seems to have a command. A transaction that receives me transaction data but doesn’t start a transaction? Actually, looking, I see it in System.Data.SQLite

// Summary:
    //     The transaction associated with this command. SQLite only supports one transaction
    //     per connection, so this property forwards to the command underlying connection.
    [Browsable(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public SQLiteTransaction Transaction { get; set; }

So, does SQLite support only one transaction period? I tried to open another connection, but then my transaction threw an exception due to a database lock. Therefore, I can not have more than one connection at a time?

+3
source share
3 answers

, , ( ).

: . . , , , . . SQLite.

+4

, , , , SQLite , ( ).

OPEN . , , , , rollback commit. . SQLite , , , , .

, savepoint.

+1

/ 1 , . , -, sql, :

public class TimeTableService
    {
        ITimeTableDataProvider _provider = new TimeTableDataProvider();

        public void CreateLessonPlanner(WizardData wizardData)
        {
            using (var con = _provider.GetConnection())
            using (var trans = new TransactionScope())
            {
                con.Open();

                var weekListA = new List<Week>();
                var weekListB = new List<Week>();

                LessonPlannerCreator.CreateLessonPlanner(weekListA, weekListB, wizardData);

                _provider.DeleteLessonPlanner(wizardData.StartDate, con);

                _provider.CreateLessonPlanner(weekListA, con);
                _provider.CreateLessonPlanner(weekListB, con);

                _provider.DeleteTimeTable(TimeTable.WeekType.A, con);
                _provider.StoreTimeTable(wizardData.LessonsWeekA.ToList<TimeTable>(), TimeTable.WeekType.A, con);

                _provider.DeleteTimeTable(TimeTable.WeekType.B, con);
                _provider.StoreTimeTable(wizardData.LessonsWeekB.ToList<TimeTable>(), TimeTable.WeekType.B, con);

                trans.Complete();
            }
        }
    }

Connection and transaction resources are automatically freed / closed using an operator statement.

In each dataprovider method you execute

using(var cmd = new SQLiteCommand("MyStatement",con)
{
   // Create params + ExecuteNonQuery
}

The TransactionScope class is new in .NET 3.5 and automatically rolls back when an exception occurs. Ease of controls...

+1
source

Source: https://habr.com/ru/post/1723957/


All Articles