This tutorial describes how to connect to InterBase and Firebird using the TIBCConnection component.
This tutorial assumes that you have installed IBDAC and run the database server and the IDE. You need to know the server address, the port number (if you use a port other than the default port 3050), the path to the database file (.gdb or .fdb), and the username and password. To connect at runtime, add the IBC unit to the uses clause for Delphi or include the IBC.hpp header file for C++ Builder.
To establish a connection to the server, set up the properties of the TIBCConnection component: Server, Port, Database, ClientLibrary, Username, and Password. You can also specify all connection parameters in the ConnectString property.
The following assumes that you have already created or opened an existing form in the IDE. At design-time, you can set up a TIBCConnection object in the TIBCConnection Editor or Object Inspector.
TIBCConnection component in the IBDAC category on the Tool Palette.
TIBCConnection object in this unit, it will be named IBCConnection1.
Using TIBCConnection Editor
IBCConnection1 object.Server edit box.3050, specify it in the Port edit box.Database edit box, e.g., D:\InterBase\employee.gdb or D:\Firebird\employee.fdb.sysdba by default) in the Username edit box.masterkey by default) in the Password edit box.gds32.dll for InterBase or fbclient.dll for Firebird — in the Client library edit box. Otherwise, skip this step.Using Object Inspector
IBCConnection1 object on the form.ClientLibrary property to gds32.dll for InterBase or fbclient.dll for Firebird. Otherwise, skip this step.Database property to the database file path, e.g., D:\InterBase\employee.gdb or D:\Firebird\employee.fdb.Password property to the password (masterkey by default).3050, set the Port property to your port.Server property to the DNS name or IP address of the InterBase or Firebird server.Username property to the username (sysdba by default).The same connection parameters at runtime are set up as follows:
Delphi
var
IBCConnection1: TIBCConnection;
begin
IBCConnection1 := TIBCConnection.Create(nil);
try
// adds connection parameters
// if Server is empty, a connection is established through the local protocol
IBCConnection1.Server := 'server';
IBCConnection1.Database := 'database';
IBCConnection1.Username := 'username';
IBCConnection1.Password := 'password';
IBCConnection1.Port := 3050;
// indicates the client lib for InterBase (for Firebird, use fbclient.dll)
IBCConnection1.ClientLibrary := 'gds32.dll';
// disables a login prompt
IBCConnection1.LoginPrompt := False;
// opens a connection
IBCConnection1.Open;
finally
IBCConnection1.Free;
end;
end;
C++ Builder
TIBCConnection* IBCConnection1 = new TIBCConnection(NULL);
try {
// adds connection parameters
// if Server is empty, a connection is established through the local protocol
IBCConnection1->Server = "server";
IBCConnection1->Database = "database";
IBCConnection1->Username = "username";
IBCConnection1->Password = "password";
IBCConnection1->Port = 3050;
// indicates the client lib for InterBase (for Firebird, use fbclient.dll)
IBCConnection1->ClientLibrary = "gds32.dll";
// disables a login prompt
IBCConnection1->LoginPrompt = False;
// opens a connection
IBCConnection1->Open();
}
__finally {
IBCConnection1->Free();
}
To open a connection at run-time, call the Open method:
Delphi
IBCConnection1.Open;
C++Builder
IBCConnection1->Open;
Another way to open a connection at runtime is to set the Connected property to True:
Delphi
IBCConnection1.Connected := True;
C++ Builder
IBCConnection1->Connected = True;
You can also set up the Connected property at design-time in the Object Inspector.
You can modify a connection by changing properties of the TIBCConnection object. Note that while some of the object's properties can be altered without changing the state of a connection, in most cases, a connection is closed when a new value is assigned to the property. For example, if you change the value of the Server property, a connection is closed immediately and you need to reopen it manually.
To close a connection, call the Close method or set the Connected property to False:
Delphi
IBCConnection1.Close;
or:
IBCConnection1.Connected := False;
C++ Builder
IBCConnection1->Close;
or:
IBCConnection1->Connected = False;
IBDAC offers a wide set of features to achieve better performance, balance network load, and enable additional capabilities, for example: