Firebird Documentation IndexFirebird 3.0 Developer's GuideDeveloping Firebird Applications in Delphi → Connection parameters
Firebird Home Firebird Home Prev: Path to the Client LibraryFirebird Documentation IndexUp: Developing Firebird Applications in DelphiNext: Working with Transactions

Connection parameters

Table of Contents

Connection Parameters in a Configuration File
Connecting to the database

The Params property of the TFDConnection component contains the database connection parameters (username, password, connection character set, etc.). If you invoke the TFDConnection property editor by double-clicking on the component, you will see that those properties have been filled automatically. The property set depends on the database type.

Figure 3.1. TFDConnection property editor

TFDConnection property editor


Table 3.1. TFDConnection component main properties

Property Purpose
Pooled Whether a connection pool is used
Database The path to the database or its alias as defined in the aliases.conf configuration file (or in databases.conf) of the Firebird server
User_Name Firebird user name. Not used if OSAuthent is True.
Password Firebird password. Not used if OSAuthent is True.
OSAuthent Whether operating system authentication is used
Protocol Connection protocol. Possible values:
  • Local—local protocol
  • NetBEUI—named pipes, WNET
  • SPX—This property is for Novell's IPX/SPX protocol, which has never been supported in Firebird
  • TCPIP—TCP/IP
Server Server name or its IP address. If the server is run on a non-standard port, you also need to append the port number after a slash, e.g., localhost/3051
SQLDialect SQL Dialect. It must match that of the database
RoleName Role name, if required
CharacterSet Connection character set name
Additional Properties:
Connected Used to manage the database connection or check the connection status. This property must be set to True in order for the wizards of other FireDac components to work. If your application needs to request authentication data, it is important to remember to reset this property to False before compiling your application.
LoginPrompt Whether to request the username and password during a connection attempt
Transaction The TFDTransaction component that will be used as default to conduct various TFDConnection transactions. If this property is not explicitly specified, TFDConnection will create its own TFDTransaction instance. Its parameters can be configured in the TxOptions property.
UpdateTransaction The TFDTransaction component that is to be used as default for the UpdateTransaction property of TFDQuery components, unless explicitly specified for the dataset. If this property is not specified explicitly, the value from the Transaction property of the connection will be used, unless it is explicitly specified for the dataset.


Connection Parameters in a Configuration File

Table of Contents

A Typical Configuration File

Since the connection parameters, except for the username and password and possibly the role, are usually common to all instances the application, we will read them from the configuration file:

xIniFile := TIniFile.Create(xAppPath + 'config.ini');
try
  xIniFile.ReadSectionValues('connection', FDConnection.Params);
finally
  xIniFile.Free;
end;
        

A Typical Configuration File

Typically, the config.ini file contains the following lines:

  [connection]
  DriverID=FB
  Protocol=TCPIP
  Server=localhost/3051
  Database=examples
  OSAuthent=No
  RoleName=
  CharacterSet=UTF8
          

You can get the contents of the connection section by copying the contents of the Params property of the TFDConnection component after the wizard finishes its work.

Note

Actually, the common settings are usually located in %AppData%\Manufacturer\AppName and are saved to that location by the application installation software. However, it is convenient for the configuration file to be stored somewhere closer during the development, for instance, in the application folder.

Note that if your application is installed into the Program Files folder and the configuration file is located there as well, it is likely that the file will be virtualized in Program Data and issues could arise with modifying it and reading the new settings subsequently.

Connecting to the database

Table of Contents

A Little Modification

To connect to the database, it is necessary to change the Connected property of the TFDConnection component to True or call the Open method. You can use the Open method to pass the username and password as parameters.

A Little Modification

We will replace the standard database connection dialog box in our application and allow users to make three mistakes while entering the authentication information. After three failures, the application will be closed.

To implement it, we will write the following code in the OnCreate event handler of the main data module.

// After three unsuccessful login attempts, we close the application.
xLoginCount := 0;
xLoginPromptDlg := TLoginPromptForm.Create(Self);
while (xLoginCount < MAX_LOGIN_COUNT) and
      (not FDConnection.Connected) do
begin
  try
    if xLoginPromptDlg.ShowModal = mrOK then
      FDConnection.Open(
        xLoginPromptDlg.UserName, xLoginPromptDlg.Password)
    else
      xLoginCount := MAX_LOGIN_COUNT;
  except
    on E: Exception do
    begin
      Inc(xLoginCount);
      Application.ShowException(E);
    end
  end;
end;
xLoginPromptDlg.Free;
if not FDConnection.Connected then
  Halt;
          

Prev: Path to the Client LibraryFirebird Documentation IndexUp: Developing Firebird Applications in DelphiNext: Working with Transactions
Firebird Documentation IndexFirebird 3.0 Developer's GuideDeveloping Firebird Applications in Delphi → Connection parameters