I've found that either one of these will lock the database:

            mstrSQL = "PRAGMA locking_mode = EXCLUSIVE;BEGIN EXCLUSIVE;"
            mstrSQL = "PRAGMA locking_mode = EXCLUSIVE;BEGIN EXCLUSIVE;COMMIT;"

and that closing the connection a little while later (eg. 0.25sec)

            mcmd.Connection.Close() 

releases it. I read in one place that you need a transaction eg. SELECT * FROM 
Utilities WHERE RecNo = 1   for locking to occur, but this database locks 
without one.

Jonathan

On 24 Apr 2013, at 11:58am, "J Trahair" <j.trah...@foreversoftware.co.uk> wrote:

> I had closed the connection after the COMMIT, but it works great if I don't.

Your problem is not with closing the connection but with the COMMIT.  The BEGIN 
goes with the COMMIT.  When you go 'BEGIN EXCLUSIVE' you do have your exclusive 
lock, but only until you have finished that transaction.  And 'COMMIT' is one 
way to finish a transaction, so the 'COMMIT' releases the lock.  So your 
procedure for locking a database for a quarter second is

BEGIN EXCLUSIVE
    do anything you want here for a quarter second
COMMIT

You should definitely do the COMMIT eventually, of course.  UNLESS you want to 
cancel the transaction.  But closing the connection plays no part in this.

Simon.

-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.3272 / Virus Database: 3162/6269 - Release Date: 04/23/13

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

Reply via email to