I did a full text search of my code and I cannot find such a line for the "working" database. If it MUST be connected, where can this happen?
If you have a databasename in the Object Inspector set, and have it as Active or Connected = true, then this could cause problems.
Your database is then connected
during development and when you start your program outside the IDE, it
gets connected automatically.
I normally advise against this. You would need to hardcode the databasename in the Object Inspector but don't have any chance to change it in code (because it autoconnects
on startup). When you move the database to another location (or your program to another drive), it would still connect to the old database (resulting in an error).
Normally I advise against using 'live' databases during development, so you can set and change the databasename during initialization of your DataModule.
For instance:
procedure TDataModule1.DataModuleCreate(Sender: TObject);
begin
// read the database connection string (server and name) from an INI file
Db := <read it here>
IBDatabase1.DatabaseName := Db; // Connected should be set as false in Object Inspector
IBDatabase1.Connected := true;
end;
You could also put this in a separate function if you don't want to connect on startup.
If you are using a 'live' database connection during development you need to be aware that you do.
That means a hardcoded databasename and no need (or even possibility) to do TDatabase.Connected := true;
procedure TDataModule1.DataModuleCreate(Sender: TObject);
begin
if IBDatabase1.Connected then IBDatabase1.Connected := false; // disconnect old database
// now the connection is false, you can set and change TIBDatabase properties
// read the database connection string (server and name) from an INI file
Db := <read it here>
IBDatabase1.DatabaseName := Db; // Connected should be set as false in Object Inspector
IBDatabase1.Connected := true;
end;
But... if you do it like this... you need to be aware that when starting your program, the database in IBDatabase1.DatabaseName, needs to be available at all times, even when moving your program. Or you need to set the Connected to false before compiling your final program to move it to another location or computer.
TIBDatabase will always disconnect automatically on shutdown of your program. So there is no need to do IBDatabase.
But if you want to do it properly:
procedure TDataModule1.DataModuleDestroy(Sender: TObject);
begin
IBDatabase1.Connected := false; // will also check if connected and disconnect if needed
end;