Offlining Connection (FireDAC)

From RAD Studio
Jump to: navigation, search

Go Up to Working with Connections (FireDAC)

Describes how to use the FireDAC offline mode, which allows you to work with data without a persistent connection to a database.


The FireDAC offline mode is similar to a multi-tier client, where most of the time a client is disconnected from a database. The connection is active only when a client needs to exchange data with a database. This is useful when an application works in an unstable environment or needs to preserve the DBMS resources.

In offline mode, a connection to a database is closed. However, the datasets are opened.

Controlling Offlining

To bring a connection to the offline mode, use one of the following options:

FireDAC does not allow you to bring a connection to the offline mode automatically, because it does not know the next time when an application needs to contact a database. Therefore, this must be done by the application code. Before the connection is set to the offline mode, active datasets with result sets that have not been fetched yet perform an action specified by the FetchOptions.AutoFetchAll property.

To bring a connection to the online mode, use one of the following options:

  • Explicit call of the TFDCustomConnection.Online method.
  • Implicit activation, when a connection needs to talk to a DBMS, by either executing a command or posting updates and so on.
Note : The value of ResourceOptions.AutoConnect must be True, otherwise an exception is raised.

If a dataset has the ResourceOptions.PersistentFileName property specified, then at the Open call, the connection is not required for the dataset. It loads the content from the specified file.

Note: Bringing the connection to the offline mode and then to the online mode is similar to recovering a broken connection in the sense that a database session state is lost. For more details, read the Recovering Connection article.

See Also