简体   繁体   中英

C# program freezes when updating sqlite record

I need help ,

I have a table with only 3 records and I am trying to update one of them only,

I am trying the SQL command using an SQLite browser and it works prefectly

But when I use the same exact SQL in C# the program freezes ( No exceptions to errors just freezes ).

this is the lines:

query = new SQLiteCommand();
query.CommandText = "UPDATE athletes SET finishing_time = 123123123 WHERE epc = 'E2:00:30:73:99:02:01:31:16:70:6A:A3'";
query.Connection = m_dbConnection;
query.ExecuteNonQuery();

I tried this in a variaty of methods ,

I tried SQLite Parameters ,

I tried string fromatting and I also tried the direct approach as in above.

they all leaded to the same problem , Program FREEZES.

This is my first time with sqlite and c#.

So I hope I can find a help here.

UPDATE: I waited about 3 to 4 minutes after freezing , I get exception database is locked.

Found it ,

I had and SQLiteDataReader object that was open which causing the problem. I put the SQLiteDataReader inside using{} and the problem is solved.

I waited about 3 to 4 minutes after freezing , I get exception database is locked.

This states that there is a deadlock (or lock is not released) on your athletes table. Are there any other query that access this table? If yes, show it on your post.

If you are using the syntax BEGIN or BEGIN TRANSACTION on SQLite browser, make sure you have a corresponding COMMIT or END TRANSACTION because if the latter is missing, the lock will not be released which may be the reason why your application is unable to access the said table. To fix this, you can reset the SQLite service and make sure to avoid the said error.

Ex:

BAD (Lock will not be released)

BEGIN TRANSACTION

UPDATE athletes SET finishing_time = 123123123 WHERE epc = 'E2:00:30:73:99:02:01:31:16:70:6A:A3'

GOOD (Lock will be released)

BEGIN TRANSACTION

    UPDATE athletes SET finishing_time = 123123123 WHERE epc = 'E2:00:30:73:99:02:01:31:16:70:6A:A3'

COMMIT

EDIT: It's just an idea so no down vote please xD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM