Discussion:
[sqlite] DB-Journal
Itxaso Perez
2016-03-02 13:48:39 UTC
Permalink
Hi!

I am modifying an app which works with Visual Studio.Net + NHibernate +
SQLite

When I have a power loss or a crash in the PC it appears a DB-Journal and I
can´t open my app.
The error concerns to NHibernate but I have some questions:

- If this occurss (power loss) using only SQLite (without NHibernate), is
not a problem the opening of an app?
- How can I 'execute' the DB-Jounal file just to try to 'correct' the
database before execting NHibernate?

Thank you very much!!
Simon Slavin
2016-03-03 01:00:22 UTC
Permalink
Post by Itxaso Perez
- If this occurss (power loss) using only SQLite (without NHibernate), is
not a problem the opening of an app?
- How can I 'execute' the DB-Jounal file just to try to 'correct' the
database before execting NHibernate?
[This is a simplified explanation.]

Having a journal file on disk should not crash your app. If you are using just SQLite you should not delete the journal file.

When you use SQLite to open the database it looks for the journal file. If it finds the journal file it knows your program crashed. It looks at the contents of the database file and the contents of the journal file and uses the two together to 'rescue' the most up-to-date data possible. Then it lets your app continue as normal. You do not have to do anything special to make this happen. SQLite does it automatically.

If your app is crashing because of this journal file, the crash does not come from SQLite. It may come from NHibernate or from your app's code. It might be good to look for advice from an NHibernate forum. But if they cannot help ...

It may be possible to recover your database by using a SQLite tool. First, take a backup copies of the database and journal files ! Then, from this page

<https://www.sqlite.org/download.html>

download the 'Precompiled Binaries' for your platform. Use the sqlite3 command line tool to open your database.

OS prompt> sqlite3 mydatabase.ext
SQLite version ...
Post by Itxaso Perez
.quit
This should cause SQLite to try to recover the database. Maybe it will work. Maybe it won't work.

Simon.
Warren Young
2016-03-03 01:46:32 UTC
Permalink
Post by Simon Slavin
Post by Itxaso Perez
- How can I 'execute' the DB-Jounal file just to try to 'correct' the
database before execting NHibernate?
Having a journal file on disk should not crash your app.
It is possible that NHibernate’s SQLite driver is calling

sqlite3_config(SQLITE_CONFIG_LOG, …)

in order to catch SQLite errors. This works since most calls to sqlite3_log() signal some kind of error, so it is easy to think of the log message callback as an error handler.

But, there are a few things that SQLite reports via this mechanism such as SQLITE_NOTICE_RECOVER_ROLLBACK and SQLITE_NOTICE_RECOVER_WAL, which are not errors, just FYI notices. They should not kill the program.

Another odd case is SQLITE_ERROR with the log string containing “syntax error”, which happens when your SQL is incorrect. I log that without exiting in my programs because it just turns into an empty result set, which my program can cope with. Thus, I’d rather have the program continue running instead of immediately dying.

(I wish there were a SQLITE_SYNTAX_ERROR constant to separate this case out.)
Loading...