EntityDAC

Database Connection

Since EntityDAC is an ORM framework, it is abstracted from the database layer, and the TEntityConnection component is not a database connection component itself. It uses uniform interface for database operations, and direct interaction with the database is handled by specialized component packages. EntityDAC is designed to work with a wide set of data access components (DAC), such as Devart Data Access Components, ADO, dbExpress, IBX, FireDAC, ZEOS, FibPlus, AnyDAC etc. To provide communication between the TEntityConnection component and a particular DAC, a special class called "data provider" is used.

Data providers

Data provider is a special class that implements database operation functions needed by TEntityConnection for a particular data access component set. In order to the provider can be registered and used, either its unit has to be added to the form USES clause or the provider component has to be placed on the form.

uses
  UnidacDataProvider;

// ...

var
  Connection: TEntityConnection;
begin
  // create the connection
  Connection := TEntityConnection.Create(nil);
  // set the UniDAC data provider as the used provider
  Connection.ProviderName := 'UniDAC';
end;

Also, the desired provider can be set at design-time using the connection editor.

EntityDAC has predefined providers for most widespread component packs. Also, it is possible to create a custom EntityDAC data provider for using with any data access components. Examples of custom providers are included in EntityDAC demos.

Dialects

While some data access components are designed to work with one particular database, other can interact with various databases (Devart UniDAC, dbExpress etc.). In order to specify an exact desired database, a data provider has a special property called "Dialect".

uses
  UnidacDataProvider;

// ...

var
  Connection: TEntityConnection;
begin
  Connection := TEntityConnection.Create(nil);
  Connection.ProviderName := 'UniDAC';
  // set the exact SQL dialect
  Connection.Dialect := 'SQLite';
end;

Or the same using the connection editor.

Connection string

Taking into account that the used data access components have different sets of properties to configure a database connection, EntityDAC provides the unified method to create a connection - connection string. Connection string consists of "parameter"="value" pairs separated by a semicolon. Each pair specifies the name and value of one of the connection parameters for a given data access component.

uses
  UnidacDataProvider;

// ...

var
  Connection: TEntityConnection;
begin
  Connection := TEntityConnection.Create(nil);
  Connection.ProviderName := 'UniDAC';
  Connection.Dialect := 'SQLite';
  // set up the connection parameters using the connection string
  Connection.ConnectionString := 'DataBase=C:\demo.db3';
end;

In the connection editor.

Description of specific connection string parameters for all supported data providers you can find in the Connection String article.

Connection dialog

As it is described above, EntityDAC works with different data access components which have different connection parameters. Therefore, EntityDAC does not have a built-in connection dialog. When the LoginPrompt property of TEntityConnection is set to True, the internal connection dialog  of the used data access components will be displayed.

uses
  UnidacDataProvider;

// ...

var
  Connection: TEntityConnection;
begin
  Connection := TEntityConnection.Create(nil);
  Connection.ProviderName := 'UniDAC';
  Connection.Dialect := 'SQLite';
  Connection.ConnectionString := 'DataBase=C:\demo.db3';
  Connection.LoginPrompt := True;
  Connection.Connected := True;
end;

At design-time.

© 1997-2024 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback