sqlite - Operation cannot be completed because the database is closed

I am in the process of attaching a sqlite database in which I am getting an error of: Operation cannot be completed because the database is closed. to help isolate it, I created a brand new project.

if I use the following code, it generates the error:

[code] app.pantryOwlDB = new SQLiteDatabase
dim pantryOwlFile as FolderItem = FolderItem(SpecialFolder.Documents.Child(“Xojo”).Child(“pantry owl”).Child(“database”).Child(“pantryowl.sqlite”))

if not app.pantryOwlDB.AttachDatabase(pantryOwlFile, “db1”) then
msgbox app.pantryOwlDB.ErrorMessage

end if[/code]

if I replace the code with this, I am able to connect to the database:

[code] dim dbFile As FolderItem = SpecialFolder.Documents.Child(“Xojo”).Child(“pantry owl”).Child(“database”).Child(“pantryowl.sqlite”)

app.pantryOwlDB = new SQLiteDatabase

If dbFile <> Nil And dbFile.Exists Then
app.pantryOwlDB.DatabaseFile = dbFile

else
msgbox “unable to connect to database file.”

End If[/code]

I am interested in attaching the database to perform comparisons with another sqlite database. Anyone come across this issue when attaching a sqlite database?

thank you in advance.

You have created app.pantryOwlDB in your code but you have not connected to it before trying to attach another database to it.

I have not used the AttachDatabase functionality before but that is what jumps out at me.

Bob is correct. You need to “Connect” before you “AttachDataBase”. Also, while technically not an error, the extra folder item is not needed in your first example:

dim pantryOwlFile as FolderItem = FolderItem(SpecialFolder.Documents.Child("Xojo").Child("pantry owl").Child("database").Child("pantryowl.sqlite"))

Can be changed to this:

dim pantryOwlFile as FolderItem = SpecialFolder.Documents.Child("Xojo").Child("pantry owl").Child("database").Child("pantryowl.sqlite")

Bob & Jim,

thank you so much! connecting first before attaching the database did the trick!

I was following the example on the attachdatabase docs in which it did not indicate this.

Also, Jim, you are correct. the extra folderitem was not needed and have removed.

thank you both again.