Setting up Connections (FireDAC)

From RAD Studio
Jump to: navigation, search

Go Up to Getting Started (FireDAC)

This article guides you through the process of defining a FireDAC database connection definition. FireDAC is a multi-DBMS data access engine offering a full set of drivers for each supported DBMS. In this article we will create the connection definition for the Microsoft SQL Server Northwind demo database.


This article describes:

  • What is a FireDAC Connection Definition?: Use a FireDAC connection definition to specify the DBMS connection parameters.
  • Using the FDExplorer Utility: Use the FireDAC Explorer to create the connection parameter sets saved for system-wide usage in a centralized storage file.
  • Using the TFDConnection Design Time Editor: Use the TFDConnection design-time editor to set up connection parameters at design time.

What is a FireDAC Connection Definition?

The FireDAC components use the concept of connection definitions to submit all necessary connection parameters, like Server, Database, User_Name to the FireDAC driver level (at run time and design time). Please read the Connection Definition reference to learn all the details about the exact technical definition, like how to create a connection definition at run time using Delphi code.

FireDAC offers two basic methods to specify the connection definition at design time:

  • Create a shared and centralized persistent connection definition using the FDExplorer.
    • Later, this definition can be assigned to the TFDConnection.ConnectionDefName property.
    • For customers who know BDE, the FDExplorer is similar to the BDE Administrator tool.
  • Create a temporary connection definition using the TFDConnection design time editor, by filling the TFDConnection.Params property within the Delphi design-time editor.
    • For customers who know ADO, this editor is similar to a connection string builder.

Using the FDExplorer Utility

The FDExplorer utility is the main tool to maintain the centralized persistent connection definitions. Please read the FDExplorer reference to understand the detailed usage of this tool.

To run FDExplorer, click Tools > FireDAC > Explorer in the IDE. Then click Ctrl-N to create a new empty connection definition.

The DriverID parameter value specifies the driver you decide to use. After setting the DriverID to MSSQL, FireDAC displays the driver-specific set of parameters. For the Microsoft SQL Server, the driver-specific parameters include:

Parameter Description
Server The SQL Server server identifier. If the host only has a single default server, then this value is the host address.
Database The name of the default database.
OSAuthent If it is set on Yes, then FireDAC will use Windows authentication. If it is set on No (by default), then the MS SQL Server authentication is used.
User_Name The login user name, if OSAuthent=No.
Password The login password, if OSAuthent=No.
MetaDefSchema Default schema name. The design-time code excludes a schema name from an object name, if it is equal to MetaDefSchema.

The next screenshot shows the connection definition setup:


Press Ctrl-A to save the connection definition to the connection definition file. To test a new connection definition, click the "+" sign within the tree item. The explorer then shows the Login Dialog. After a successful login, the tree node expands and allows you to drill down into the DB objects.

Note: If you add a new persistent connection definition using FDExplorer while the Delphi IDE is running, the connection is not visible to the FireDAC design-time code. To refresh the persistent connection definition list, you need to restart the Delphi IDE.

Now the connection definition is ready for use within Delphi. Just set the value of the TFDConnection.ConnectionDefName property to the name of the newly created connection definition.

Using the TFDConnection Design-Time Editor

The TFDConnection component design-time editor is the environment used to maintain temporary connection parameters. Double-click any TFDConnection component at design time. The FireDAC package then displays the Connection Editor dialog:


The Connection Editor provides a similar functionality to the FDExplorer. Again, you should start by setting the following:

  • Driver ID - to create a temporary connection definition from scratch (our case);
  • Connection Definition Name - to create a temporary connection that overrides the parameters of an existing persistent connection.

Again, you need to fill in the parameters as specified in the chapter above. This dialog offers the following functions:

  • The Test button - to test the connection definition.
  • The Wizard button - to call a DBMS-specific connection definition wizard, if available.
  • The Revert to default button - to reset the parameters to their default values.
  • The Help button - to go to a help page with a description of the current driver parameters.
  • The Info page - to try to connect to a DBMS and obtain information about the connection.
  • The SQL Script page - to execute the SQL script commands in this connection.

After pressing the OK button of the editor, FireDAC loads the connection parameters into the TFDConnection.Params property and sets the TFDConnection.DriverName property to the chosen value.

Activate a Connection

After you have assigned a persistent connection definition name to the TFDConnection.ConnectionDefName property or filled in the temporary connection definition parameters into the TFDConnection.Params property, set the TFDConnection.Connected property to True. If the parameters are specified correctly, the connection is established.

See Also