RAD Studio for Microsoft .NET
ContentsIndex
PreviousUpNext
Connecting to the AdoDbx Client

You can establish a database connection using AdoDbx Client in several ways.

To make a connection using dbxconnections.ini file

  1. The ConnectionName property referenced in the code sample is the name of a connection in the dbxconnections.ini file.
  2. Use the following Delphi code to connect:

uses System.Data.Common
...
var
   Factory: System.Data.Common.DbProviderFactory;
   Connection: System.Data.Common.DbConnection;
begin
    Factory := System.Data.Common.DbProviderFactories.GetFactory('Borland.Data.AdoDbxClient');
    Connection := Factory.CreateConnection();
    Connection.ConnectionString := 'ConnectionName=IBConnection';
    Connection.Open;
end
To make a connection using a System.Configuration file

  1. For this to work, the property settings in dbxconnections.ini and dbxdriver.ini for the database you are connecting to must be migrated to the machine.config file. Here is an example of connection string text to add to the <connectionStrings> section of machine.config:

<add name="IBConnection" 
    connectionString="ConnectionName=IBCONNECTION;
    drivername=Interbase;
    database=workerbee:C:\Borland\Interbase\examples\database\employee.gdb;
    rolename=RoleName;
    user_name=user;
password=password;
    sqldialect=3;localecode=0000;blobsize=-1;
    commitretain=False;waitonlocks=True;interbase transisolation=ReadCommited;
    trim char=False" providerName="Borland.Data.AdoDbxClient"/>

  1. Use the following Delphi code to connect:

var
  Factory: System.Data.Common.DbProviderFactory;
  Connection: System.Data.Common.DbConnection;
  Config: System.Configuration.Configuration;
  ConnectSection: System.Configuration.ConnectionStringsSection;
  CurrentSettings: System.Configuration.ConnectionStringSettings;
begin
  Factory:= System.Data.Common.DbProviderFactories.GetFactory('Borland.Data.AdoDbxClient');
  Connection:= Factory.CreateConnection();
  Config:= System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  ConnectSection:= Config.ConnectionStrings;
  CurrentSettings:= ConnectSection.ConnectionStrings['IBConnection'];
  Connection.ConnectionString:= CurrentSettings.ConnectionString;
  Connection.Open;
end;
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!