lundi 2 mai 2016

C# System.Data.SQLite : Concurrency violation: the UpdateCommand affected 0 of the expected 1 records

I have a .net winforms application which is using SQLite DB and I am using System.Data.SQLite dll.

This is how I load a Datatable:

            DataTable table = new DataTable();
            SQLiteDataAdapter m_readingsDataTableDataAdapter;
            SQLiteCommandBuilder m_readingsDataTableCommandBuilder;

            m_readingsDataTableCommandBuilder = null;
            m_readingsDataTableDataAdapter = null;

            // Create fresh objects
            m_readingsDataTableDataAdapter = new SQLiteDataAdapter(sql, Database.getInstance().connectionObj);
            m_readingsDataTableCommandBuilder = new SQLiteCommandBuilder(m_readingsDataTableDataAdapter);
            m_readingsDataTableDataAdapter.Fill(table);
            return table;             

This data table has one primary key and no other constraints. I set it as a data source for DataGridView and after all the edits, I update the DataTable like this:

    m_readingsDataTableDataAdapter.Update(table);

Occasionally, the updates fires an error and I don't know when, it stops throwing errors - probably after system restart ( not sure ). And then, the updates go fine until another situation where this update throws an error again. When the error occurs, it happens for all updates from then on even after application restart.

Error: An unhandled exception of type 'System.Data.DBConcurrencyException' occurred in System.Data.dll Additional information: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

I would appreciate any help or questions as this is quite a critical section of my project.

Thanks.

Aucun commentaire:

Enregistrer un commentaire