Problems with re-opening a database that was modified earlier in a procedure

I often get a message that a database that a procedure opens does not exist.

This seems to happen when a file was just written and closed and needs to be reopened. The workaround seems to be to loop opening that database until its file name in found in the list generated by info(“databasefilename”). Sometimes doing this for 9999 times is not enough. Opening another dummy database first and closing it seems to reduce the number of times I get this message but does not reduce it to zero!

This also does not seem to be a systematic error. Sometimes the same error occurs when rerunning the procedures and sometimes it works without problems.

It also seems to occur more with larger databases.