ImportDatabase Bug?

This statement works: OpenDatabase folderpath(folder)+file

This statement does not work: importdatabase folderpath(folder)+file, “ExistingData”,“Replace”

The error that I keep getting is: ImportDatabase failed because database [file path:databasename] is not open, even though the database is open.

It is Monday, and I may not be seeing something I am doing wrong.

The importddatabase statement needs the name of the open database and not the file name and path. If you don’t have the database name of the open database you want to import but only the actual file name, you could adjust that by stripping the file extension from the file name which should give you the database name. Here is that change made to your code:

OpenDatabase folderpath(folder)+file
importdatabase arrayfirst(file,"."), “ExistingData”,“Replace”

If you already know the name of the open database you want to import then just use that directly in the importdatabase statement.

1 Like

Thanks, Gary.

I was starting to type a reply when Gary beat me to it. :slight_smile: Thank you Gary!

However, please note that using arrayfirst( like that assumes that the filename doesn’t have any periods in the filename. A filename like a.b.c.pandb is perfectly legal, but won’t work with Gary’s code. Probably the best bet would be not to include the .pandb extension in the file variable in the first place, the opendatabase statement doesn’t need it. Then you could use

opendatabase folderpath(folder)+file
importdatabase file,"existingdata","replace"

Also, in Panorama X you probably don’t need the folderpath( function. But that’s a whole other can of worms. See the Folder IDs section of the Files and Folders help page to open the can.

Much thanks.