How to use TpFIBDatabase FIBPlus Component to connect with Firebird database in Delphi XE4?
TpFIBDatabase component is used to make database connectivity with Firebird database in Delphi. For using TpFIBDatabase component, you should have FIBPlus and Firebird installed on your system. I am using Delphi XE4, Firebird 2.5.2 and FIBPlus 7.5 to make database connection.
Connection parameters are typical for InterBase/Firebird server:
1) path to a database file;
2) user name and password;
3) user role;
4) charset;
5) dialect;
6) client library (gds32.dll for InterBase and fbclient.dll for Firebird).
To connect to a database you should call the Open method or set the Connected property to True. It’s also possible to use this code to connect to a database:
function Login(DataBase: TpFIBDatabase; dbpath, uname, upass, urole: string): Boolean;
begin
if DataBase.Connected then DataBase.Connected := False;
with FDataBase.ConnectParams do begin
UserName := uname;
Password := upass;
RoleName := urole;
end;
DataBase.DBName := dbpath;
try DataBase.Connected := True;
except
on e: Exception do
ShowMessage(e.Message);
end;
Result := DataBase.Connected;
end;
To close the connection either call the Close method or set the Connected property to False.
You can also close all datasets and connected transactions at once:
procedure Logout(DataBase: TpFIBDatabase);
var i: Integer;
begin
if not DataBase.Connected then
Exit;
for i := 0 to DataBase.TransactionCount - 1 do
if TpFIBTransaction(DataBase.Transactions[i]).InTransaction then
TpFIBTransaction(DataBase.Transactions[i]).Rollback
DataBase.CloseDataSets;
DataBase.Close;
end;
No comments:
Post a Comment