db.Close vs db = Nil

I had serious data base troubles recently with Data Base.



did not worked for some reason…

Before jumping from the balcony, after loosing hope, I tried:

db = Nil

and all of a sudden, my troubles disappeared. And after some times of debug, the project appears to work fine now.

Ventura / 2021r2.1 / SQLite.

Maybe db is already Nil and you are trying to Close a Nil database? I always use:

If db <> Nil Then db.Close

at the end of my Methods. Never been a problem for me.

No David.

db.Close was not enough.

things are far better since I used db = Nil. Now, I can click many different times (successive) to Sort by Columns (0 and 1)… The Sort is done by SQLite.
Prior to that, the sort is done, but leads to error messages (RS is Nil or so…).
There may be a max number of open db… (where db.Closed do not decrease it)…

NB: I checked very carefully all code in the window: each and every db instance is correctly Closed.
But when I implemented the SortColumn Event Code, I had to Nil the db in the SortColumn Event Code where I init and use it.

And I do not checked - yet - the project on Windows 10.

somehow .Close is related to .Connect

why Xojo can’t use

connect & disconnect
open & close

i don’t know …


1 Like

Some database engines won’t execute a Close if there are still transactions that haven’t been either committed or rolled-back. Perhaps you still had an unresolved transaction somewhere.

Hi Dale,

thank you for your input.

Some database
I use SQLite.

Unresolved transaction
No. This cannot be so. These happens on read operations and I close them carefully asap. A second read can be done far later…