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)

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

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Community Member Profile Picture
    on at

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

  • Suggested answer
    gorkem ozdogan Profile Picture
    40 on at

    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);

  • Preeti Sonambekar Profile Picture
    1,245 on at

    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.

  • Community Member Profile Picture
    on at

    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
    1,245 on at

    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

  • Florian DITTGEN Profile Picture
    15 on at

    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

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans