On Sun, Jan 29, 2012 at 12:57:21 +0200, Shahar Weinstein wrote:
> I don't think that the TMP folder is the right direction but I'll check it
> anyway with the hosting company.

No, *NOT* *HOSTING* *COMPANY*. Your code.

I agree it's probably not the right direction though.

> besides that, I do know that there is only one process running that tries
> to write to the database what makes my situation a sad joke. sqlite
> supposed to be a strong database that knows how to deal such simple
> situations.

So you are saying, that there is absolutely no other client using the code at
the same time or even that the same client isn't using two windows? Because
otherwise any serious web server will run mutliple instances of your code in
either multiple threads or multiple processes.

> even of 2 processes that tries to write to the database the same time, else
> it's probably a very weak database system that doesn't have transactions
> locks mechanism inside.

It DOES. But very coarse-grained and is telling you the one process has it
locked, so the other process can't access it.

Sqlite is designed to be lightweight. The cost for this is, that it does not
have per-row or per-table locks. A write transactions always needs to lock
the whole database. Additionally by default when the database is locked, the
operation immediately fails with the "database is locked" error you are
seeing.

You need to do three things:

 - Run 'PRAGMA journal=wal' on the database once (see
   http://www.sqlite.org/wal.html). This requires sqlite at least 3.7.0.
 - Set the timeout, so the operations wait for the other process to finish
   for some time instead of failing. The C-level API is sqlite3_busy_timeout
   (http://www.sqlite.org/c3ref/busy_timeout.html). The .NET api will be
   called similar.
 - Plan eventual migration to SQL Server or MySQL or something, because
   sqlite will not scale. It's designed to be fast for data processing and
   small so it can be embedded in desktop or even mobile applications, but
   that means it does not support multiple servers and parallel transactions.
   It can work fine in web app that gets at most few hits a minute, but for
   higher load you will definitiely need a database server.

-- 
                                                 Jan 'Bulb' Hudec <b...@ucw.cz>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to