This article describes the power of combining the AnyDAC with the
RemObjects Data Abstract. AnyDAC is the leading Delphi DBMS access engine and RemObjects Data Abstract is a very powerful multi-tier framework.
This tutorial has two main sections:
The
Data Abstract relies on the
Data Abstract drivers to access to a specific DBMS. The Data Abstract drivers are implemented by wrapping a specialized data access framework (DAF). While this approach works just great, it has a few consequences:
AnyDAC as a Data Abstract driver provides superb integration with Data Abstract on a very low level, giving extra speed in the interaction of the two. The AnyDAC rounds off the RemObjects Software offering of the Data Abstract by adding an in-house solution for the "last mile", the data access layer which previously always depended on third parties. And it does that without giving up the flexibility. The combined product benefits are:
In this section we will review how to build a Data Abstract driver connection string. A connection string is a set of the DAD parameters, allowing you to establish a connection to a DBMS.
Note: Use the DASM -> Schema -> Drivers menu item to see the AnyDAC DAD version info. This info is required to be provided to the technical support, if you contact them regarding AnyDAC DAD usage.
In this part we will review step by step how to configure a connection to a Microsoft SQL Server using the AnyDAC DAD. We will use the
Data Abstract Schema Modeler Connection Wizard to build the connection string. So, lets run the DASM and press New Connection on the Connections pane. In general, you can follow to the instructions shown on the right of the Connection Wizard dialog:
Basically, at this point you should be able to connect to the DBMS. You can verify that by pressing the Test Connection button.
The general format for the AnyDAC DAD connection string is:
AnyDAC?AuxDriver=<AnyDAC driver ID>;Server=<server>;Database=<database>;UserID=<user name>; Password=<password>;<AnyDAC DAD specific parameters>;<AnyDAC driver specific parameters>
So, for the above example, the connection string is:
AnyDAC?AuxDriver=MSSQL;Server=127.0.0.1;Database=Northwind;UserID=sa;Password=;Schemas=1
The connection string may be specified at design time or at runtime using the
TDAConnectionManager component. Set the Default property to True to use this connection as the default. To link the AnyDAC DAD driver to your application, do one of the following:
These parameters are used by the AnyDAC DAD to control the DAD behaviour and are not visible to the AnyDAC drivers. The following table lists the parameters:
|
Parameter |
Description |
Example value |
|
ConnectionDefName |
Allows to specify AnyDAC connection definition name, instead of specifying AnyDAC driver separate parameters in connection string. |
MSSQL_Demo |
|
BiDirectionalDataSets |
AnyDAC DAD dataset mode:
|
1 |
|
DirectMode |
AnyDAC DAD mode:
|
1 |
|
Integrated Security |
SSPI - set OSAuthent=Y connection definition parameter. Is used only for SQL Server connections. |
SSPI |
|
Schemas |
1 - forces DAD to return object names prefixed with schema. Is used only for SQL Server connections. |
1 |
|
DataTypeSchema |
FIB - forces DAD to use FIB+ compatible data type mapping. Is used only for IB/FB connections. |
FIB |
These parameter names must be prefixed by the '@' sign and are transferred directly to an AnyDAC driver to establish a connection to a DBMS. Check AnyDAC Database Connectivity for details.
Alternatively, you can specify connection definition by the ConnectionDefName parameter. Also to specify Format, Fetch, Update and/or Resource options:
For example, AnyDAC connection definition with options:
[AnyDAC_DAD]
Database=Northwind
Server=127.0.0.1
DriverID=MSSQL
FetchOptions.AssignedValues= [evMode]
FetchOptions.Mode= fmAll
FormatOptions.AssignedValues= [fvMapRules]
FormatOptions.OwnMapRules= True
FormatOptions.MapRules= < item NameMask = 'MY_BOOL' SourceDataType = dtInt16 TargetDataType = dtBoolean end>
And the extended connection string:
AnyDAC?AuxDriver=MSSQL;Server=127.0.0.1;Database=Northwind;UserID=sa;Password=;Schemas=1;
@FetchOptions.AssignedValues=[evMode];@FetchOptions.Mode=fmAll;
@FormatOptions.AssignedValues=[fvMapRules];@FormatOptions.OwnMapRules=True;
@FormatOptions.MapRules=< item NameMask = 'MY_BOOL' SourceDataType = dtInt16 TargetDataType = dtBoolean end>;
Or
AnyDAC?AuxDriver=MSSQL;@ConnectionDefName=AnyDAC_DAD;
Since 5.0.31.701 version in the Data Abstract AnyDAC driver was introduced new working mode so-called Direct Mode. The Data Abstract driver Direct Mode excludes a TDataSet descendants overhead and allows to use low-level high-speed DAF APIs. While the standard driver mode is the Dataset Mode, it uses the DAF specific TDataSet descendants.
In the Direct Mode the AnyDAC DAD uses the Phys and DatS layers directly, excluding the Comp and DApt layers overhead. That gives 20-40% performance gain. Note that:
Using direct mode is managed by parameter DirectMode, setting DirectMode=1 enables direct mode, setting DirectMode=0 disables direct mode. The Direct Mode is turned off by default, as it is not 100% backward compatible. You need to explicitly analyze the application and, if possible, to turn Direct Mode on.
The main difference between the two modes is, that in the Direct Mode the DAD does not use the TDataSet descendant objects. So, IDASQLCommand.Dataset and TDACustomField.BindedField are always nil. While it is not a limitation for a Data Abstract server, it may be an issue with local usage. Anyway, in DirectMode=1 you can use the TDACustomField.BindedNativeField instead of TDACustomField.BindedField and IDASQLCommandNativeObject.
Known limitations in DA 5.0.31.701:
In this section we will review the migration of the application to AnyDAC DAD from any other DAD.
In general, you should perform the following steps:
There are possible issues:
This article has provided the benefits of combining Data Abstract and AnyDAC to get premier N-tier data access solutions. The articles describes all aspects of the AnyDAC DAD usage.
|
What do you think about this topic? Send feedback!
|