AnyDAC
ContentsIndexHome
PreviousUpNext
Using Data Abstract with AnyDAC

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.

Group
Links
1. General

This tutorial has two main sections:

  • Benefits of combining AnyDAC and Data Abstract: while each of the products is a state of the art solution for the specific tasks, together they allow to solve these tasks more effectively.
  • How to use the AnyDAC Data Abstract driver (DAD): explains how to configure AnyDAC DAD, how to use Direct Mode and how to migrate to AnyDAC DAD from other DADs.

 

2. Benefits of combining

 

Data Abstract

 

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:

  • Any underlying DAF has to be be highly effective, so the combined product is also highly effective. Otherwise a DAF is only a weak link in the chain.
  • To access to the multiple DBMSs effectively you will need to use the few specialized DAFs. If they are commercial products, the combined tool price is raising with the addition of an access option to each new DBMS. Also, the developers will need more time to get an expertise in all these DAFs with different APIs.
  • The usage of a single unified DAF, as ADO or DbExpress (DBX), is cost effective and simple for the developers, but it is not really a high speed solution (as we will show later). Also, these DAFs hide many useful DBMS features, making combined solution less flexible.

 

Together

 

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:

  • Performance:
    • The Data Abstract, AnyDAC and AnyDAC DAD - all three - were optimized and adjusted to each other to get maximum performance.
    • The AnyDAC DAD is the fastest Data Abstract driver, implementing Direct Mode, giving 20-40% performance gain, while the CPU load is largely reduced.
  • Features:
    • The AnyDAC DAD implements all the optional Data Abstract driver interfaces.
    • The AnyDAC DAD supports many DBMSs in an effective, unified and feature rich way.
  • Price:
    • You need to buy only a single DAF, instead multiple ones.
  • Support. The AnyDAC DAD is developed and maintained together by the Data Abstract and AnyDAC teams. So, the expertise and resources of each team is fully accessible to the other team. That means:
    • Both products are getting features for better interoperability.
    • You will never hear "Sorry, this is not our issue".
    • Always up-to-date builds of the Data Abstract and AnyDAC DAD.

 

3. How to use

 

Configure connection

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. 

 

Using DASM Connection Wizard

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:

  • Step 1. Specify AnyDAC as Driver Name.
  • Step 2. Because AnyDAC DAD provides access to the different database systems, using own drivers, you should choose the AnyDAC driver ID as Aux Driver. In our tutorial it is MSSQL.
  • Step 3. Specify a MS SQL Server name in Server Name. For example, 127.0.0.1 for a locally running default MS SQL Server instance.
  • Step 4. Provide user credentials. If you use Windows Authentication, check that Custom Parameters (Step 6) has Integrated Security=SSPI; specified. Otherwise, delete this parameter. We use 'sa' as a Login Name with empty Password.
  • Step 5. Specify a MS SQL Server database name. For example, Northwind.

Basically, at this point you should be able to connect to the DBMS. You can verify that by pressing the Test Connection button. 

 

 

  • Step 6. Here you can specify the custom driver parameters. You can press the button on the right of the Parameters edit box to get a help dialog, containing a list of the supported driver specific parameters. We use Schemas=1.
  • Step 7. Now specify your connection name and press the OK button to save the connection.

 

By code

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:

  • drop TDAAnyDACDriver to any form or data module in your application;
  • include uDAAnyDACDriver into any uses clause in your application.

 

4. Custom parameters

 

DAD specific parameters

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:
  • 0 - use unidirectional datasets (by default). This allows to speed up fetching and preserve memory usage for large result sets.
  • 1 - use bidirectional datasets. This allows you to walk through AnyDAC DAD datasets in both directions.
 
DirectMode 
AnyDAC DAD mode:
  • 0 - standard mode, when DAD implements a IDADataset interface using TDataSet descendants.
  • 1 - direct mode. AnyDAC implements it using high-speed low level data access interfaces.
See next chapter for details. 
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. 
DataTypeSchema 
FIB - forces DAD to use FIB+ compatible data type mapping. Is used only for IB/FB connections. 
FIB 

 

AnyDAC specific parameters

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:

  1. Start ADExplorer and setup a connection definition.
  2. At the Advanced options page set up the required options.
  3. Save the connection definition.
  4. In ADConnectionDefs.ini copy the saved options and append them to the connection string preceding them with "@" symbol.

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;

 

5. Direct mode

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:

  • the same driver supports the Direct and Dataset modes;
  • the driver behaviour remains almost the same in either of the modes.

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:

  • DASM doesn't support DirectMode=1 for configuring schema so it is recommended to set up your schema in DASM with DirectMode=0 and after this to switch into DirectMode=1.
  • TDABinDataStreamer doesn't support DirectMode=1.

 

6. Migration

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:

  • Replace the connection string with an AnyDAC compatible one.
  • If your application works directly with an underlying data access framework, this code must be changed to an AnyDAC compatible one.

There are possible issues:

  • An AnyDAC DAD data type mapping may be different from the other DADs. If you are migrating from FIB+ DAD, just use the DataTypeSchema=FIB connection parameter to force the FIB+ data type mapping in the AnyDAC DAD. For other DADs, please contact us.
  • An AnyDAC DAD behavior may be different from the other DADs. For example, AnyDAC offers the same range of transaction control features, just through a different API.
  • The AnyDAC may not contain the DBMS specific components, which other data access frameworks have, for example, IBDump from FIB+.

 

7. Summary

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!