Deleting a database file

We are using a REALSQLdatabase in a program and want to load a different database and delete the previous file. I keep getting a 104 error on the delete even after loading a different database file. How to stop the previous file from being “in use”?

TIA

have you closed the connection?

I guess not. When we open a new database we do
EMDB.databaseFile = GetFolderItem(newname)
EMDB.Connect()

I guess that doesn’t close the old connection?

Nope. You need to do a specific Close on the database.

EMDB.Close should do it.

So:

EMDB.Close
then delete the file
EMDB.databaseFile = GetFolderItem(newname)
EMDB.Connect()

Does that look right? The file deletes without error and I have to get the database back on line right away or I get an avalanche of database errors

why are you getting “an avalanche of database errors”?
nothing is accessing either database in that scant fraction of a second that that connection switches…

Right That was my point. I had to reconnect in the same method that deleted the file before leaving the method. That method had gone to another to get the user’s confirmation on the deletion, which went to another to get the database name. I put a separate confirmation dialog in the first function so we don’t try to access the database while it’s closed.

Ah, my first go at answering a question, don’t know if I am right or wrong but I use a button with the following code and it works well.

[code] dim result as integer

result = msgbox (“Are You Sure you want to DELETE the DATABASE ?”,36)
if result=6 then
app.golfer.close
Dim f as Folderitem
f=SpecialFolder.ApplicationData.Child(“TGC”).Child(“Golf”).Child(“golfer.rsd”)
f.Delete()
If f.LastErrorCode > 0 then
MsgBox Str(f.LastErrorCode)
Else
MsgBox “DataBase Deleted, Program must be Restarted to Create NEW Database”
window.close
End if
exit
end if[/code]

It’s probably best to change

f=SpecialFolder.ApplicationData.Child("TGC").Child("Golf").Child("golfer.rsd")

to

f = app.golfer.DatabaseFile

just so you know for sure that you’re accessing the right file. If you change the path or name later on, you don’t have to remember to update this code, too.

Thanks Tim.