Search code examples
asp.netsql-serverasp.net-mvcsql-server-2008petapoco

SQL Server Transaction rollback or commit using Petapoco?


I have list of rows for insert to database within a transaction using Asp.Net. But it will not commit fully. That means the last fews rows are only inserted.

My code is:

using (PetaPoco.Database db = new Database("Mydb"))
{
    using (var trn = db.GetTransaction())
    {
        foreach(var r in rowlist)
        {
          db.Save(r);
        }

        trn.Complete();
    }
}

For example rowlist has 20 elements, but some first elements are not inserted using Petapoco. But it will happen very rarely that means very slow network connection.


Solution

  • I don't think that the problem it's in the transaction or Petapoco.

    Two guesses:

    1. Maybe the list is not posted in full due to slow connection?
    2. Are you aware that db.Save updates or insert depending on the object configuration and ID value? Maybe the last records are updated over the first one inserted