On Fri, 13 Mar 2009 14:17:12 +0530, "Chaitali"
<chaitali.chattopadh...@cesc.co.in> wrote:

>I am using SQLite database on Windows XP Professional as a back-end for my
>application in VB6. Generally SQLite is functioning satisfactorily except
>for a few instances when the database is getting corrupted. In one such case
>of corruption the data from two tables got intermingled. In another case I
>am getting the prompt "Database disk image is malformed". Since this is
>causing data loss I would like to know how do I recover my data in case of
>such a scenario 

First of all: save a copy of the database and journal, so
you can retry any of your steps.

- Restore from a recent backup 
        This is the only reliable way.

You may be able to rescue some data in one or more of these
ways:
- Try to dump the database
        echo .dump |sqlite3 dbname >all.sql
- Try to dump table by table
        echo .dump tblN|sqlite3 dbname >tblN.sql
- SELECT a range of rows using LIMIT,
        avoiding broken ranges

> and secondly how to avoid such occurrence ?

- Use the latest SQLite: v3.6.11
- Make sure you don't use dangerous PRAGMAs, 
        like PRAGMA synchronous=OFF;
- Use transactions (BEGIN / COMMIT) 
- Handle errors in your app
- Do NOT delete journal files
- make sure there is enough diskspace for
        = database
        = journal (in the database directory)
        = temp files (in /tmp)
- Check your hardware

See also:
http://www.sqlite.org/lockingv3.html#how_to_corrupt
http://www.sqlite.org/cvstrac/wiki?p=DatabaseCorruption
http://www.sqlite.org/atomiccommit.html
 

>Thanks and regards
>
>Chaitali
-- 
  (  Kees Nuyt
  )
c[_]
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to