Database closed problem - Fixed

I have an .sqlite file on a USB stick. After I have loaded the file and then try to connect to the database I get the following: “Operation cannot be completed because the database is closed.”

Is it closed because it is on a USB stick (doubtful)? Anyway, how on earth can I open it? I have a couple of apps that deal with databases (including Paul’s excellent SQLVue), and they can all open said database, so it is obviously possible. My code follows:

[quote] Dim dbFile As New FolderItem(Volume(Vol).Child(“MyDb.sqlite”))
If dbFile = Nil or dbFile.Exists = False Then
MsgBox(“Could not find database on disk.”)
Exit
End If

checkClasses = New SQLiteDatabase
checkClasses.DatabaseFile = dbFile

If checkClasses = Nil Then
MsgBox(“Can’t Load Database”)
End If

sql = “SELECT * FROM classesBackup WHERE specialSelection = 0”
data = checkClasses.SQLSelect(sql)
If checkClasses.Error Then
MsgBox(checkClasses.ErrorMessage)
End IF
If data <> Nil Then
While Not data.EOF
data.MoveNext
Wend
data.Close
End If[/quote]

The database is loaded OK, the problem occurs when I try to SELECT something from the database. I know currently I am not doing anything in the While Not data.EOF loop, but I have to clear up this problem first.

I managed to get this to work by creating a databaseSetup Shared Method (very much like the example in Eddies Electronics). I have no idea why it didn’t work when I had the database setup in the Open Event of my app, and I have no idea why it works in the ShareMethod. But it works.

I can see you’re not connecting to the database in the Open Event. Setting the databasefile doesn’t actually connect to the db.

Thanks Wayne, that most surely was the reason. I can’t see that what you mentioned is the problem, but obviously you are correct, and by putting the database connection code in a Shared Method at the same level as the App did in fact fix things. I am just so happy that this is working after fiddling and cursing for the last 12 hours or so. Now I can get on with the rest of the app - which would have been a waste of time until I could use the database.