Page 1 of 1

SQLite connection drops occasionally

Posted: Tue Oct 08, 2019 7:36 pm
by MichaelBluejay
Seems like about every 4-5 hours LC loses the connection to the database and returns an error. (I don't remember the text of the error.) At that point I run the openDatabase handler again and then everything's fine.

Seems like the solution is just to call openDatabase at the top of any handler that's accessing the database. Seems a little clumsy to be constantly refreshing the db connection, but I presume it will work.

Any insight into this problem?

Code: Select all

local dbID

command openDatabase
   put "/full/path/to/theData.data" into tDatabasePath
   put revOpenDatabase("sqlite", tDatabasePath, , , , ) into dbID
end openDatabase

Re: SQLite connection drops occasionally

Posted: Thu Oct 10, 2019 2:23 pm
by Klaus
Hi Michael,

no idea why this happens, but since connecting to a local SQLite database takes
literally one or two milliseconds in LC, I started to open and close the db before
and after every access a couple of years ago and had no problems with that ever since.


Best

Klaus

Re: SQLite connection drops occasionally

Posted: Thu Oct 10, 2019 5:43 pm
by cpuandnet
Hi Michael,

The technique I often use to minimize this issue, no matter which database i use, is to have a function on the stack script that returns the database id. In that function, you can check whether or not the database is open. If the database is not open, then call the openDatabase command. This way, you don't even need to call the openDatabase during initialization because it will get called the first time you use the getDatabaseID function.

Code: Select all

local dbID

command openDatabase
   put "/full/path/to/db" into tDatabasePath
   put revOpenDatabase("sqlite", tDatabasePath, , , , ) into dbID
end openDatabase

function getDatabaseID
   if dbID is not among the items of revOpenDatabases() then
      openDatabase
   end if
   
   return dbID
end getDatabaseID

Re: SQLite connection drops occasionally

Posted: Fri Oct 11, 2019 11:23 pm
by MichaelBluejay
Okay, thank you very much.