In C#, SQLite randomly throws "Constraint failed\r\nColumn ... is not unique" -
i'm using entityobjects in c# , backend sqlite. system information:
windows xp (up-to-date), vs2010 premium, system.data.sqlite 1.0.88.0 (3.7.17)
the table schema is:
create table [transaction] ( [primary_key_col] integer primary key autoincrement, [transaction_code] int not null, [account_code] int not null, [category_code] int not null, [transaction_date] date not null, [description] varchar(50));
public partial class transaction : entityobject
represents table.
to add new transaction, call following code:
transaction transaction = new transaction() { description = _desc, transaction_code = generatehash(_desc), account_code = _acccode, category_code = _catcode, transaction_date = datetime.now }; dbentities.transactions.addobject(transaction); dbentities.savechanges(system.data.objects.saveoptions.acceptallchangesaftersave);
works fine after adding few rows, following exception:
constraint failed\r\ncolumn account_code not unique.
if exit application , restart it, error goes away randomly comes again.
i know account_code not unique, never asked unique!!!
there 3 specific ways application can create transaction , exception thrown rather randomly of these methods. sqlite? (i'm new sqlite). idea why happening? i've pulled out hair ...
as per comment seems have done trick:
are using "new" dbentities context every time insert or re-using same 1 multiple inserts? shouldn't matter either way try former if using latter.
Comments
Post a Comment