DAXSPOT

Wednesday, November 1, 2023

How to execute SQL directly form Dynamics AX X++

How to execute Sql directly form Dynamics AX X++

Reference by : alirazazaidi


Dynamics Ax provide many other ways to communicate with database, but sometimes we have to execute direct query to database. For example I have to delete all items form InventTable of particular company or dataArea. I execute it as follow.


Connection      connection;

Statement       statement;

str             query;

DataAreaId      currentDataArea; 


// create connection object

connection = new Connection();


// create statement

statement = connection.createStatement();


//Find current company

currentDataArea = curext();


if(! Box::yesNo(“You are in Company: ” + currentDataArea + “. Proceed to Delete?”,DialogButton::No))

{

return;

}


//Vendors delete

query = “delete from inventTable where dataAreaId = ‘” + currentDataArea + “‘”;

new SqlStatementExecutePermission(query).assert();

statement.executeUpdate(query);

CodeAccessPermission::revertAssert();


info(“InventItems Deleted from Company: ” + currentDataArea);

Report deployment error "No report data table with name exists in report schema for data provider"

ISSUE:

When you deploy the report in Dynamics AX 2012 or D365F&O and you try to view the report and get the error "no report data table with name exists in report schema for data provider".

SOLUTION:

Just restart your report server service from the services console and the error will be resolved.

Thank you,

Sunday, October 22, 2023

Error Cannot create a record in Entity (DMFEntity)

Solution:

Simply delete all records in DMFEntity table.

Note: delete only the entity which you are working on and then rebuild and sync your project.


There are a lot of other related error:

Severity    Code    Description    Project    File    Line    Suppression State

Error        Infolog diagnostic message: 'Error synching entity metadata for entity - KRTProductEntity. Message -    at Microsoft.Dynamics.Ax.MSIL.Interop.throwException(Int32 ExceptionValue, interpret* ip)            0    

Error        at Dynamics.AX.Application.DmfDataPopulation.syncEntityUpdate(DMFEntity dmfEntity, DictDataEntity dictDataEntity)            0    

Error        at Dynamics.AX.Application.DMFEntity.insert() in xppSource://Source/ApplicationFoundation\AxTable_DMFEntity.xpp:line 433            0    

Error        Infolog diagnostic message: 'Cannot create a record in Entity (DMFEntity). Entity: Items, KRTProductStaging.            0    

Error        at Dynamics.AX.Application.DmfDataPopulation.syncEntityUpdate(DMFEntity dmfEntity, DictDataEntity dictDataEntity, Boolean useTargetEntityName, Boolean @useTargetEntityName_IsDefaultSet) in xppSource://Source/ApplicationFoundation\AxClass_DmfDataPopulation.xpp:line 947            0    

Error        at Dynamics.AX.Application.DmfDataPopulation.syncEntityMetadata(StringCollection dataEntityViewCollection, StringCollection compositeEntityList) in xppSource://Source/ApplicationFoundation\AxClass_DmfDataPopulation.xpp:line 794.' on category 'Error'.            0    

Error        at Dynamics.AX.Application.DmfDataPopulation.syncEntityCreate(DictDataEntity dictDataEntity, Boolean useTargetEntityName, Boolean @useTargetEntityName_IsDefaultSet) in xppSource://Source/ApplicationFoundation\AxClass_DmfDataPopulation.xpp:line 899            0    

Error        at Dynamics.AX.Application.DmfDataPopulation.syncEntityCreate(DictDataEntity dictDataEntity, Boolean useTargetEntityName)            0    

Error        at Microsoft.Dynamics.Ax.Xpp.Common.Insert()            0    

Error        at Microsoft.Dynamics.Ax.MSIL.cqlCursorIL.insert(IntPtr table)            0    

Error        at Microsoft.Dynamics.Ax.Xpp.NativeCommonImplementation.Insert()            0    

Error        Database synchronization failed. You may have to do a full build of the package 'K3Retail' and all of its dependent packages.            0    

Error        The record already exists.' on category 'Error'.            0    


class DeleteDMFEntity

{        

    public static void main(Args _args)

    {      

        DMFEntity dmfEntity;

        DMFTargetXML dmfTargetXML;

 

         //ttsbegin;

        delete_from dmfEntity;

        delete_from dmfTargetXML;

 

         /*while select forupdate dmfEntity

        {

            dmfEntity.delete();

        }*/

        //ttscommit;

        info('Done');

    }

}

Thank you,

How to execute SQL directly form Dynamics AX X++

How to execute Sql directly form Dynamics AX X++ Reference by : alirazazaidi Dynamics Ax provide many other ways to communicate with databas...