Search code examples
sqlitedelphifiredac

What has to be done to switch database file in connection in sqlite/delphi


I hope this is not some embarrassing user error, but here goes:

I want to change the database parameter for the connection and reopen it. This code continues to display (and allow for editing of) the original table connection rather than refreshing. Is there some kind of 'flush' or refresh I must call?

dmMain.conMain.close;
dmMain.conMain.Params.Values['Database'] := secondDatabase;
dmMain.conMain.Open;
dmMain.tblTimings.Active := true;

I subsequently tried conMain.Connected := false to no effect.


Solution

  • This should not happen (all linked datasets should be closed), so I would call it a bug (you're doing it right in your code). See the Close method description:

    TCustomConnection.Close

    Closes the connection.

    Call Close to disconnect from the remote source of database information. Before the connection component is deactivated, all associated datasets are closed. Calling Close is the same as setting the Connected property to false.

    In most cases, closing a connection frees system resources allocated to the connection.

    Note: If a previously active connection is closed and then reopened, any associated datasets must be individually reopened; reopening the connection does not automatically reopen associated datasets.