Subject Re: [IBO] Closing the IB_Connection
Author Paul Vinkenoog
Hi Jason,

> What is the proper way to close a connection? I am using the
> IBOAdmin components to do a restore, but I can't seem to close the
> database.

You do (try to) close the database _before_ you do the restore, I

> No matter what I do I get an error. I have tried all of the
> following.
> ForceDisconnect;
> CloseTransactions;
> Disconnect;
> Close;

The standard way is Disconnect.

> I get Error : lock time-out on wait transaction. object <database
> path> is in use could not drop database <database path> (database
> might be in use)

You get a "could not drop" error if the database is in use and you
- try to drop (delete) it, or
- try to restore a backup over it.

> I have no pending statements at the time of this close down attempt
> - can anyone give me a snippet of delphi code for properly shutting
> down the current apps connection to the DB? and if there is a way to
> close down all connections to the db perhaps with a warning first, I
> could really use that info.

You can shut down all connections with e.g.

gfix -sh -tr n my_db.fdb

where n is the timeout in seconds.

If there are still unfinished transactions after n seconds, the
shutdown fails. You can then force it with

gfix -sh -f n my_db.fdb

After doing your thing, bring the database back online with

gfix -o my_db.fdb

By the way, the usual practice is to restore to a *new* file, not to
overwrite the existing db. If the restore succeeds, try to rename the
existing file to e.g. my_old_db.fdb. If the rename succeeds, nobody
was connected. If not, shut down using gfix and retry the rename.

Once the old db has been renamed, rename the restored db to the
original name. Then reconnect.

Paul Vinkenoog