Page History
...
It may seem a simple thing to switch databases at will, but it's not if any OAMs are shared. That is, if you are using the same file in multiple databases. When switching a database and there are shared OAMs you must close every file that has been used, including Code-File Lookups, triggers, etc. it is easy to miss a file. If you don't do this the original database will be accessed. That is, the database is set when the File is opened. After that, all IO will go to the original database. When using a single form, a CLOSE is all that is required to close all the files that have been used. When multiple objects are used, it is far more complex. It's essential that all Components and Functions exit back to the initial Component/Function, ensuring that any HEAVYUSAGE objects call CLOSE before returning. In fact using LIGHTUSAGE Functions and Dynamic Components everywhere may be the best solution. The following is an example of the code that would need to be executed in the initial component if that component accesses any files:
Subroutine Name(SwitchSRV) Parms(#SwitchSRV)
Define Field(#LastSRV) Reffld(#SERVER1)
Close
If ('#Switchsrv *NE #Lastsrv')
If ('#LastSRV *NE *BLANK')
Use Builtin(Disconnect_file) With_Args(* #LastSRV)
Endif
Use Builtin(connect_file) With_Args(* #SwitchSRV)
Endif
#LastSRV := #SwitchSRV
Endroutine
Note that if you have multiple databases connected with files under commitment control, a COMMIT or ROLLBACK will commit or rollback all transactions on all databases.