web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Change Data Capture with AX 2009?

(0) ShareShare
ReportReport
Posted on by 75
We have a situation where we need to feed information from AX 2009 to a BI-solution, the "Change Data Capture" functionality in SQL Server 2008 would be a good fit for this but we're wondering if it's supported? The CDC-configuration requires some changes to tables within AX and what happens when you deploy new versions (table definitions, documents and so on)? Anyone got an answer? /andreas

*This post is locked for comments

I have the same question (0)
  • GoFast Profile Picture
    200 on at

    Andreas,

    Can you provide more info on the process and use case?  What data are you tracking/sending?

  • Andreas Pettersson Profile Picture
    75 on at
    We're tasked with providing (at a minimum) new entries and updated entries in five different tables (CustTable, LedgerTable, LedgerTrans, CustInvoiceJour, CustInvoiceTrans). We probably need only a subset of data from CustTable since the BI-solution only needs customers referenced in the other tables we provide. The current requirement is to deliver data to a separate SQL Server-instance on a daily basis but that might change depending on how flexible the final solution turns out to be. We do not have any requirements regarding deletes against any of the involved tables but that might change as well. One possible design for this is to use CDC on the base tables, develop an SSIS-package to read from CDC-views and deliver delta-changes to the second SQL Server-instance that has closely matched tables. After that we're not involved in the process anymore. Thanks for your interest and hopefully some answers. /andreas
  • Glen Hassell Profile Picture
    225 on at

    Hi Andreas,

    Is the BI solution within the same network? How is it placed within your network / domain structure?

    My reason in asking such a question, the way that I would go about this for a remote data source is to create a web service at the receiving end (where the BI data source is located) and provide a WSDL reference. Take the URL of the web service and add to the AOT under \References - a new reference (modified with service configuration editor to suit your binding requirements) and consume the WSDL.

    From there I would have a class that makes a reference to the generated assembly that AX will produce and call this with Interop in code;

    try
        {
            permission = new InteropPermission(InteropKind::CLRInterop);
            permission.assert();

           // logic based on loop to fetch required records - counter++;

         }

    The class that you would design in X++ could be called OnUpdate or done periodically as a Batch job. Depending on how you wire it up.

    This is one way of going about the process but may not be the right suit, based on your needs. Another way would be to identify all data from all sources in SQL and using a different database to the AX database (let's call it BIDB), select the data required from a stored procedure held within the BIDB periodically, once selected into your new database, initiate a connection to the BI data source and insert or update the records to their or reverse the process and pull the data from your BI data source.

  • Andreas Pettersson Profile Picture
    75 on at
    Hi Hassell,

    Thanks for your interest, we've already opted for the pure DB/SSIS solution. It would have been perfect to use CDC in SQL Server 2008 but we couldn't get an answer if it's supported from any MS officials. It's a bit strange that the Dynamics division doesn't seem to pick up on a lot of new features in the base platform. I thought that MS pushed new platform capabilities quite hard but that might not be the case within Dynamics.

    Anyhow - thanks again.

    /andreas
  • Community Member Profile Picture
    on at

     FYI:  All writes to Dynamics AX db tables MUST be done within AX or with extreme caution!  AX performs several functions usually associated with a db (relations, delete action restrictions, field typing, index definition control) and adds the RecId / RecVersion values. 

    Inserts perfomed outside AX can result in an invalid RecId and AX ignoring the record. 

    Edits peformed outside AX can violate the relationships defined in AX and cause errors/over-writes of data - the latter can occur on the next update from withing AX, making debugging a wee bit trickier.

  • Community Member Profile Picture
    on at

    Please do more research before implementing the following.
    CDC Implementation - Prerequisites

    • SQL Server Agent Service should be running in order to get notified of the CDC actions
    • Enable CDC for database by a member of the sysadmin fixed server role·        
    • Enable CDC for individual table by the members of the db_owner fixed database role

    CDC Implementation - Steps  

    1. Enable CDC for the database
    use <Database>

    GO

    exec sys.sp_cdc_enable_db

    GO

    A new column is_cdc_enabled is added to sys.databases table. To check whether the CDC has been enabled for a database: select is_cdc_enabled from sys.databases
    where name = ‘<Database>

    --1GO

    Once CDC has been enabled for a database, a new schema named ‘cdc' and a new user named ‘cdc' will be created. Also, following 5 new tables will be created                              

    • cdc.captured_columns

    Contains one row for each column tracked in a capture instance. By default, all columns of the source table are captured. However, columns can be included or excluded when the source table is enabled for change data capture by specifying a column list.

    • cdc.change_tables

    Contains one row for each change table in the database.

    • cdc.ddl_history

    Contains schema modifications to source table

    • cdc.index_columns

    Contains one row for each index column associated with a change table. The index columns are used by change data capture to uniquely identify rows in the source table. By default, the columns of the primary key of the source table are included. However, if a unique index on the source table is specified when change data capture is enabled on the source table, columns in that index are used instead. A primary key or unique index is required on the source table if net change tracking is enabled.

    • cdc.lsn_time_mapping

    Contains one row for each transaction having rows in a change table. This table is used to map between log sequence number (LSN) commit values and the time the transaction committed. Entries may also be logged for which there are no change tables entries. This allows the table to record the completion of LSN processing in periods of low or no change activity.

    2. Enable CDC for the table

    exec sys.sp_cdc_enable_table

    @source_schema = 'dbo' --mandatory

    ,  @source_name   = 'Employee' --mandatory

    ,  @role_name     = 'cdc_test'  --mandatory

    ,  @supports_net_changes = 1

    ,  @index_name = N'PK_Employee_EmployeeID'

    ,  @captured_column_list = N'EmployeeID,EmpName, EmpCity'

    ,  @filegroup_name = N'PRIMARY';

    GO

    @source_schema = Is the name of the schema to which the source table belongs. source_schema is sysname, with no default, and cannot be NULL.

    @source_name = Is the name of the source table on which to enable change data capture. source_name is sysname, with no default, and cannot be NULL.

    source_name must exist in the current database. Tables in the cdc schema cannot be enabled for change data capture.

    @role_name = Is the name of the database role used to gate access to change data. role_name is sysname and cannot be NULL. If the role currently exists, it is used. If the role does not exist, an attempt is made to create a database role with the specified name.

    @supports_net_changes = Indicates whether support for querying for net changes is to be enabled for this capture instance.

    supports_net_changes is bit with a default of 0. If 0 or if not specified, only support for querying for all changes is allowed. That is, only the system functions to query for all changes are created.

    If 1, the system function to query for net changes is created in addition to the system function to query for all changes. If supports_net_changes is set to 1, index_name must be specified, or the source table must have a defined primary key. The columns defined in index_name or in the primary key are used to uniquely identify a row in the source table. These columns are added to the table cdc.index_columns.

    @index_name = The name of a unique index to use instead of the primary key index to uniquely identify rows in the source table. index_name is sysname and can be NULL. index_name must be a valid unique index on the source table.

    @captured_column_list = Identifies the source table columns that are to be included in the change table. captured_column_list is nvarchar(max) and can be NULL. If NULL, all columns are included in the change table. Column names must be valid columns in the source table. Columns defined in a primary key index, or columns defined in index_name must be included.

    captured_column_list is a comma-separated list of column names. Individual column names within the list can be optionally quoted with either 'or []. If a column name contains an embedded comma, the column name must be quoted.

    captured_column_list cannot contain the following reserved column names: __$start_lsn, __$end_lsn, __$seqval, __$operation, and __$update_mask as these are the metadata columns to allow interpretation of the change activity in the ‘change table'.

    captured_column_list cannot contain columns defined with a data type introduced in SQL Server 2008.

    @capture_instance = Is the name that you assign to this particular CDC instance; you can have up two instances for a given table. (default:schema_sourcetable)

    @filegroup_name = Is the filegroup to be used for the change table created for the capture instance. filegroup_name is sysname and can be NULL. filegroup_name must exist in the current database. If NULL, the default filegroup is used. A separate filegroup is recommended for creating change data capture change tables keeping the speed of data retrieval in the view.

    To check whether the CDC has been enabled for a table:

    select is_tracked_by_cdc from sys.tables

    where name = ‘<tablename>'

    Note: If you make any schema changes to the table, you need to disable CDC at the table level and then re-enable it in order to capture changes to the data for the new columns.

    To disable CDC on a table -

    exec sys.sp_cdc_disable_table

      @source_schema = 'dbo',

      @source_name = 'Employee',

      @capture_instance = 'dbo_Employee'

     (or 'all', if you have more than one capture_instance name)

    SQL Agent Jobs:

    When the first table in a database has been enabled for change data capture, two new jobs are created and started by SQL Server Agent, as mentioned below -

    Job 'cdc.TestDb_capture' started successfully.

    Job 'cdc.TestDb_cleanup' started successfully.  

    A capture job is created using the default values when the first table in the database is enabled for change data capture and no transactional publications exist for the database. When a transactional publication exists, the transactional log reader is used to drive the capture mechanism, and this separate capture job is neither required nor allowed.

    The cleanup job is created using the default values when the first table in the database is enabled for change data capture.

    cdc.TestDb_capture job:

    This job scans the database transaction log to pickup changes to the tables that have CDC enabled. The first step of the job is to raise an error event to the client indicating the start of the change data capture session using the T-SQL command RAISERROR(22801, 10, -1) and queries sys.messages for id = 22801.  Once this is done, it executes the system stored procedure [sp_MScdc_capture_job] to start the Change Data Capture Collection Agent.

    cdc.TestDb_cleanup job:

    This SQL Server job purges the change tables periodically by executing the system stored procedure sys.sp_MScdc_cleanup_job.

    Please note that the capture job should be kept running in order to capture changes to the source tables and the cleanup job is scheduled to run at regular intervals to remove the data from the change table. If the SQL Server agent or the capture job is stopped for any reason, all the changes that happened during this period will get captured from the transaction log when the job is started again.

    Audit (Change Data) Table

    When a table has CDC enabled, a new change table is created which corresponds to the main table. When the name of the change table is not specified at the time the source table is enabled, the table is named as: cdc.capture_instance_CT where capture_instance is the combination of schema name of the source table and the source table name in the format schema_table. (Ex: cdc.dbo_Employee_CT).

    This table contains some book keeping columns such as __$start_lsn, __$end_lsn (always populates with NULL; may be there for future use), __$seqval, __$operation, and __$update_mask.

    The column __$operation has various codes as shown below -

    Insert                                                  - 2

    Update (row with before image) - 3

    Update (row with after image)     - 4

    Delete                                                 - 1

    Data consumers access change data through table-valued functions (fn_cdc_get_all_changes_<capture_instance> & fn_cdc_get_net_changes_<capture_instance>) rather than by querying the change tables directly.

    In general, querying for all changes is more efficient than querying for net changes. If, for example, you know that the change data will consist entirely of inserts, a query for all changes using the 'all' row filter option and a query for net changes using the 'all' or 'all with mask' option will return essentially the same resultset. The performance of the cdc.fn_cdc_get_all_changes_<capture_instance> function, however, is likely to be significantly better. If a primary key or unique index is not defined for a table, only queries using the cdc.fn_cdc_get_all_changes_<capture_instance> function are supported. 

    The function cdc.fn_cdc_get_net_changes_<capture_instance> returns only one change per row. If multiple changes are logged for the row during the request interval, the column values will reflect the final contents of the row.

    Data is requested for changes having commit log sequence numbers (LSNs) that lie within a specified range. If a source row had multiple changes during the interval, each change is represented in the returned result set. In addition to returning the change data, four metadata columns provide the information you need to apply the changes to another data source. Row filtering options govern the content of the metadata columns as well as the rows returned in the result set. When the 'all' row filter option is specified, each change has exactly one row to identify the change. When the 'all update old' option is specified, update operations are represented as two rows: one containing the values of the captured columns before the update and another containing the values of the captured columns after the update.

    For further details refer MSDN link below

    http://msdn.microsoft.com/en-us/library/cc627369.aspx

  • Glen Hassell Profile Picture
    225 on at

    Andreas,

    SSIS and loading a datamart is obviously a lot cleaner than even trying to read the above... ha!

    Web services and interop are useful only if you can be bothered with the .Net passage, which although it has advantages, the cleanest and most obvious is the good old datamart and load into SSAS or whatever your BI tool of choice is from the processed clean data, which you can process peridocily with the Agent.

    CDC really is a nice looking feature but for now perhaps it's more intelligent to stick to a prooven humanly understood path ;-) ---- p.s for a moment I thought you meant the cult of the dead cow - cdc....

  • Kevin Maguire Profile Picture
    5 on at

    Attunity CDC does not require any changes to your SQL Server DB, it does not require storage tables on the source and doesn't require any new software to be loaded on your source server.  Replicate Dynamics/SQL Server data in minutes with CDC for SSIS.

     http://www.attunity.com/sql_server_cdc_for_ssis

     There is a free evaluation available.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans