Hi All,
I have an application which starts two or more threads.
Each thread open a separate connection to the database and in each transaction, modifies various tables of it. I use third-party library to access the SQLite database which make it possible to have an uniform access to different DBMS. I do not control directly the calls to sqlite3 funcution, but I have the source code of the library so I can see the sequence of calls.

The sqlite3 version I am using is 3.7.9 .

The sequence of actions of a thread is the following:

    //--- Start Thread ---
    ....

    // Open connection to DB
    sqlite3 *handle(NULL);
sqlite3_open_v2("C:...\dbase", &handle, SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_FULLMUTEX|SQLITE_OPEN_READWRITE );
    sqlite3_busy_timeout(handle, 30000);

    sqlite3_step("PRAGMA foregn_keys = ON");
    sqlite3_reset(..)
    sqlite3_clear_bindings(..);

    // Begin a new transaction
    BEGIN TRANSACTION EXCLUSIVE
        ...
       SELECT ....
        INSERT ...
        UPDATE ...

    COMMIT
...
    // Begin a new transaction
    BEGIN TRANSACTION EXCLUSIVE
        ...
       SELECT ....
        INSERT ...
        UPDATE ...
        ...
    COMMIT

    sqlite3_close();

    //--- END Thread ---


When I have four or more threads accessing to the database I see the error message: "database table is locked". This happens when a thread begins a new Transaction, probably because another thread already has an excluse access to the database.

I supposed that, setting the "busy timeout" to an high value (30 secs in my case) should manage this kind of problems, but probably I am wrong or I am not using sqlite functions in the right way.

 Can any one suggest me any strategies for overcome this problem ?

Tank you for your help.

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to