Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

How to pass ado.net objects (e.g. DataReader) into AX custom class using .net business connector in C#

Posted on by 1,245

Hi...

Sorry, some how I am unable to post questions on my old post, so its a new thread I am opening for further communication.

I wrote all my T-SQL code inside a job to import data into 6 user tables in AX ERP. The job executes perfectly fine and imports the data correctly. But when I copy-paste the same code inside my custom class method and call it from my C# code using business connector I get the following error.

"{Microsoft.Dynamics.BusinessConnectorNet.XppException: Method 'execute' in COM object of class 'ADODB.Connection' returned error code 0x80040E31 (<unknown>) which means: Query timeout expired.
   at Microsoft.Dynamics.BusinessConnectorNet.Axapta.CallStaticClassMethod(String className, String methodName, Object[] paramList)
   at Microsoft.Dynamics.BusinessConnectorNet.Axapta.CallStaticClassMethod(String className, String methodName, Object param1, Object param2)"

The code I used to call my custom AX class/method inside c# code looks like this.

object retVal = axapta.CallStaticClassMethod("myInsertClass", "myInsertMethod", taxType, 2);

Please suggest.

Thanks,
Preeti

*This post is locked for comments

  • Florian DITTGEN Profile Picture
    Florian DITTGEN 15 on at
    Re: How to pass ado.net objects (e.g. DataReader) into AX custom class using .net business connector in C#

    Hello Preeti,

    I'm not sure if that what you are trying to do is a good idea (why not directly executing the queries in your application via ADO.Net, but if it is what you need to do, I would suggest:

    - using ADO.Net in your X++ code: floditt.blogspot.com/.../using-adonet-with-x.html

    - Increase the timeout of the SqlConnection and SqlCommand

    - you might whant to increase the connection timeout in the Connection-String:

    msdn.microsoft.com/.../system.data.sqlclient.sqlconnection.connectionstring.aspx

    Hope this helps :-)

    Kind regards,

    Florian

  • Preeti Sonambekar Profile Picture
    Preeti Sonambekar 1,245 on at
    Re: How to pass ado.net objects (e.g. DataReader) into AX custom class using .net business connector in C#

    Hi, the T-SQL code inside job works fine when run from inside AX. But when I call the job using my business connector like this: axapta.CallJob("Job7");

    I get the following error: "The method has been called with an invalid number of parameters.(C)\Jobs\Job7".

    If I do the following:

    AxaptaObject Args = axapta.CreateAxaptaObject("myArgs");

    axapta.CallJob("Job7", Args);

    I still get the following error:

    "System.ArgumentException: The supplied method arguments are not valid."

    Please suggest. When I pass this AxaptaObject parameter, how the parameter is defined inside the job? Because it does not accept AxaptaRecord parameter?

    Please help.

    Thanks,

    Preeti

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: How to pass ado.net objects (e.g. DataReader) into AX custom class using .net business connector in C#

    I fail to see why you would want to use AX to run COM/NET code and then call this using the business connector from a C# (.Net) program...

    Why do you not call the database insert from your C# code directly?

  • Preeti Sonambekar Profile Picture
    Preeti Sonambekar 1,245 on at
    Re: How to pass ado.net objects (e.g. DataReader) into AX custom class using .net business connector in C#

    Hi,

    I have 6 queries to retrieve data from 6 tables in intermediate database and then import them into 6 AX ERP tables. Total no. of records to be imported in 6 tables is around 1900000. When I run the job I get the following error:

    Method 'execute' in COM object of class 'ADODB.Connection' returned error code 0x80040E31 (<unknown>) which means: Query timeout expired.

    how do we increase connection timeout in AX class? The example code in the job is below for one of the tables (out of 6).

      COM adoConn;

      COM recordSet, recordSet1, recordSet2;

      COM fields;

      COM field;

      COMVariant fieldValue;

      ;

      adoConn = new COM("ADODB.Connection");

      adoConn.open("Provider=SQLNCLI;Server=(local);Database=myDB;Trusted_Connection=yes;");

      recordSet = adoConn.execute("CREATE TABLE #Temp(TaxGroupID VARCHAR(25), TaxRecID BIGINT IDENTITY(0,1) NOT NULL)");

      recordSet1 = adoConn.execute("insert into #Temp(TaxGroupID) select top 10 taxgroupid from taxgroup");

      recordSet2 = adoConn.execute("insert into DynamicsAX1..myUserTable(TaxGroupID,recversion, recid) select TaxGroupID, 1, TaxRecID from #Temp");

    One of the tables has 1238767 records out of 1900000 and mostly I get the error for this. When I run the job by commeting this piece of code which imports 1238767 data, then job executes successfully. But when I include this table, I get timeout expired. Once I get this exception, then even if I comment this part of code again, it keeps on throwing the same exception and I have to restart Sql Server Services.

    Please suggest.

  • Suggested answer
    gorkem ozdogan Profile Picture
    gorkem ozdogan 40 on at
    Re: How to pass ado.net objects (e.g. DataReader) into AX custom class using .net business connector in C#

    as i can understand you can update some records in a job

    , but when you transfer to in a method it fails..

    are you sure that is your axapta class correctly initialize in c# ..

    alternativetly you can call your job  from c# either if it can helps you ..

    ex:

    axapta.callJob("JobName", args);

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: How to pass ado.net objects (e.g. DataReader) into AX custom class using .net business connector in C#

    What happens when you call the job using the business connector?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,151 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans