Closing a Shared, Secret File

Based on a previous thread, what I know about secret and shared databases, and Help, it would seem that synchronize would be an un-necessary command after opening the file, and that setactivedatabase might not be necessary, but would not be problematic to include.

In a procedure that opens a shared file, then a single user file, both as secret windows, followed by importdatabase to load the shared data into the unshared file, I’m getting inconsistent results and a wide variety of errors.

Sometimes it works. More often the error is a ‘field or variable does not exist’ error from Panorama but they vary: ActiveProcedure, loggingToServer, hostServer, localCoverage, asyncCallbackLabel… The error may or may not include dimmed menus that require a ForceQuit.

In the simplest code I could pare it down to it’s closing the shared file that sets up the error.

opensecret “SharedFile”
If Error rtn EndIf
opensecret “SingleFile”
If Error
    setactivedatabase “SharedFile” 
    closefile
    If Error nop EndIf
    Rtn
EndIf
setactivedatabase "SingleFile" 
importdatabase "SharedFile","ExistingData","Replace",“MatchingFields”,“YES”
Save
setactivedatabase "SharedFile"  
closefile            ; <- eliminate this and there’s no issue 
If Error nop EndIf

I don’t want the shared file to remain open so how can I close it without an issue?

Which brings up another question. Is there a way to determine what databases are open if they’ve been opened as Secret Windows?

Update: I’ve confirmed that by eliminating all references to CloseFile for the shared file, my full procedure runs over and over without issues. The single-user file can be closed without causing subsequent errors.

Jim, I reported the same issue over a year ago at the end of this thread, unfortunately without a proper fix:

My workaround is to open the datasheet and then close the database, like this:

setactivedatabase "SharedFile"
opensheet
closefile

Our applications heavily rely on secret shared files, and this solution works great.

The info(“files”) function is suppose to return a list of open files. I have found that often (always?) files I have closed from the File menu or procedurally are still listed as being open. Indeed, if I use:

setactivedatabse “My File”
opensheet

The data sheet for My File will pop open. How do I actually close those files. I don’t mind them remaining open secretly, but it does bother me to know that closefile is acting more like makesecret. Maybe it is only me or only certain files…don’t know for sure.

You’re right. That does work. Unfortunately it defeats the use of secret windows.

But thanks for leading me to that thread. With a bit more experimentation I have found an apparent solution to closing a shared secret file using CloseDatabase instead of CloseFile:

SetActiveDatabase "Contacts"  
Save
CloseDatabase "Contacts"

The Save is necessary.

The info(“files”) function that Gary suggested is not showing the secret file among the open files. All is good.

There must be something extra going on you are unaware of. There is no way the info(“files”) function could possibly list a file that is not currently open.

If the Always keep database open option is checked (in the Database Options window) then clicking on the window’s close box will make the database secret. But using the File>Close command would still close the database, as would doing so procedurally.

I probably was not clear on this point. By using info(“files”) I verified that the supposed closed files were still actually open secretly. My example of using opensheet to have the data sheet pop open also verified that the file was still in memory. And, no, the option to keep the file open even if the last window was closed was never checked on any of my files.

This was not a big issue for me and I only noted it in passing to see if anyone else had run across this situation. Since I seem to be the only one seeing this I can only assume it is something particular to my setup and files. Certainly not worth any more time on my part or yours.

Perhaps. But based on your original post where you said this often (or perhaps always) happens, it sounds like you can probably duplicate this on command. If that’s true, I’d like to know how you did it, and hopefully try to recreate it. Maybe it’s only happening with particular databases? I’ve provided some additional background below as to why I don’t understand how this could ever happen. But interacting with Apple’s NSDocument class is very complex so it’s always possible I’m not understanding some edge situation.


The closefile statement is really only three lines of code:

  1. Find out what the current database is.
  2. Unlock the current record in that database if it is unlocked.
  3. Call Apple’s code to close the document (which is what Apple calls a file)

If the database has any windows open, it’s actually Apple’s code that closes them, not code written by ProVUE.

If you use File>Close Database, there is one situation where that won’t close the database - if a procedure is already running. However, in that situation it also won’t close the windows, it won’t do anything other than just beep.

If there isn’t any procedure currently running, then again, the entire close operation is handled by Apple, including closing any windows.


You were completely clear, and I understood what you were getting at with opensheet. It sounds like you cannot ever close any database except by quitting Panorama? Is that correct?

I would ask you what the Memory Usage window shows, but that window uses info(“files”). If info(“files”) lists the file, then it is definitely open in memory. There is only one way to enumerate open databases, and that method is used by info(“files”) and any other code that needs to know about open databases.

Upon some further experimentation it seems that the problem is only with two files I use pretty much weekly. After restarting Panorama X and loading the other files I normally have open with my current project and then opening and closing those two problem files, they close properly. Sometime latter I reopened the two files and did a batch of data entries and then tried to close the files again. One file would not even close its only open window and the other would close its windows but stayed in memory. Closing the first file’s only open window did not close the file.

These are two files loaded with my personal financial info so I can not share them. I haven’t had the time or inclination to spend making copies and trying to strip the confidential info out and then testing again.

Exactly, they will not close until I quit Panorama. Since this only involves these two files, I prefer not to spend more time experimenting looking for other clues that may still not point to anything of value.