USER_NAME
USER_NAME

Reputation: 1037

Sqlite - failed to connect database

Background:
1. Its a c# application using Sqlite databse
2. This application creates empty db if db is not present and sync data to it from server.

Problem:
1. Application is getting crashed abruptly sometimes. looks like there is some unhandled exception.
2. Even I am relaunching the application its immediately getting crashed.

Temporary Solution:
1. Copy db to other location and delete the original db.
2. Run the application. No crash. Since no db is present, empty db is getting created by application.
3. Copy back the backup db and woo hoo Application starts fine without any crash.

My Questions:
1. How application is working with the same old db as It was crashing the application earlier repeatedly?

Note:
1. I failed to reproduce this crash in debugging as I dont know the in which scenario it is getting failed.
2. Any input will be appreciated so dont hesitate to guess the solution.

Prediction:
1. Some supporting temp files are in inconsistent state and causing the problem while connecting to db and when we are creating a new database with the same name then these files are being overwritten with the fresh consistent new files.

Upvotes: 1

Views: 2084

Answers (2)

Kirill Gamazkov
Kirill Gamazkov

Reputation: 3397

Probably, someone is hurting database file. Maybe it's your own app if it contains several threads, or if you starting several instances simultaneously. By default SQLite is able to handle these cases, but there are configuration options that can make it not thread-safe. Take a look at documentation. Or, maybe, your application modifies the database file directly, bypassing SQLite (check the paths you're using).

Maybe SQLite fails to create write-ahead log file near the database, which results in unrecoverable database corruption if the application is killed while some transactions are active.

SQlite's database format is documented, so you can compare valid and corrupted file and figure out what part of it is broken.

As a last resort, you can use SQLite's source code to build your own lib with debug info.

Upvotes: 1

MCollard
MCollard

Reputation: 956

First of I want to say that I think that nobody can answer your question without any code or error.

  1. Any input will be appreciated so dont hesitate to guess the solution.


So i'll just throw this in here:

There are many things that can make your application crash or give errors like:
- Application is not consistent
- Database creation goes wrong in your application
- rights?
- connection goes wrong before even doing anything
- Connection goes wrong because the path is wrong
- Connection goes wrong because your database doesn't exist
- Syncing goes wrong

Have you tried looking at the pc's log?
Have you updated everything you are working with.
From your description I guess that somewhere in your code u make a change to your database, which makes your whole application fail.

Note: 1. I failed to reproduce this crash in debugging as I dont know the in which scenario it is getting failed.

So you can get the crash when you run the application normally, but when debugging you are not able to reproduce it. Does this happen on only your computer or does this also happen in other enviremonts

I know this is probably not the answer you're looking for but you can check all of this if u want.(if needed I will delete it)

Good luck!

Upvotes: 2

Related Questions