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)

X++ Call Stored Procedure on external DB to populate local DB - best practice / implementation

(0) ShareShare
ReportReport
Posted on by

Hi Folks,

just a question regarding best practice.

I have an external DB with an SP.

I wish to call the SP and insert the result into a local table.

I'm guessing an AX Class with straight X++ code to call the SP directly would be fine?

ie. there is no other better practice or implementation I should consider?

appreciate your thoughts.

Rgds,

K,

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    The question is what you mean when you're talking about "an AX class". OdbcConnection?

    You may consider one of .NET APIs for working with databases, such as LINQ to SQL. It's probably not worth the overhead if your case if simple, but the fact that it can generate objects from return values, you get compile-time control, IntelliSense etc. may be critical in complex scenarios.

  • Community Member Profile Picture
    on at

    Hi Martin,

    Yes, I was just going to create a new class and then use ODBC connection.

    Thats for highlighting the potential use of .NET APIs / LINQ, will take that under consideration, still designing.

    Thanks!

    Rgds,

  • Community Member Profile Picture
    on at

    Hi,

    I've have ran into what may or may not be an AX issue, allow me to outline.

    I have SQL DB Server on Domain1 with a SQL Auth login.

    I have AX-Dev Server (and Client) on Domain2.

    I have setup my ODBC DSN on my AX-Dev Server, the DSN can connect and validate to the DB on Domain1 using the SQL Auth Login.

    I can also connect to the DB on Domain1 from AX-Dev Server using SQL MS.

    However, when I use the DSN from within AX (X++ Job) it states:

    ODBC operation failed.

    Unable to log on to the database.

    [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

    Object 'OdbcConnection' could not be created

    Is there anyway i can work around this?

    Any suggestions to fix?

    thanks always,

    k.

  • Community Member Profile Picture
    on at

    wouldnt ya know it, i bang my head off a wall for 2 hours, post up, and then my next idea fixes it:

    Problem code:

    loginProperty.setDSN('myDSN');

    odbcConnection = new ODBCConnection(loginProperty);    

    Successful code:

    login = strFmt('UID=%1;PWD=%2;DSN=%3','myUser','myPass','myDSN');

    loginProperty.setOther(login);

    odbcConnection = new ODBCConnection(loginProperty);    

    interesting that using the working and tested DSN directly throws the error.

    anyways, thanks for listening :)

    K.

  • Community Member Profile Picture
    on at

    HI folks,

    just coming back around on this for a bit more direction.

    So I have my ODBC connection and i can execute my sql statement and receive my expected ResultSet. all is good here.

    I have an AOT table that contains the correct fields which represents the result set.

    Apart from creating my own column by column, row by row mapping method which inserts the resultset rows one by one, is there any other better to get my resultset into the table?

    thanks.

    rgds,

    K.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    That's exactly where more sophisticated solutions such as ADO.NET Entity Framework and LINQ to SQL may help, e.g. by generating strongly-typed classes representing records and columns.

  • Community Member Profile Picture
    on at

    found this, looks good tutorial ;)

    dev.goshoom.net/.../connection-to-external-database

    thanks Martin.

    K.

  • Community Member Profile Picture
    on at

    (decided to go manually first, before enhancing with ADO (which actually looks great)).

    having the following problem :/

    only X is getting persisted to the table.

    in debug i can see Y being assigned, but its never persisted.

    any idea?

    rgds, K.

           ttsBegin;

           while(resultSet.next())

           {

               select forupdate stageData;

               stageData.X= resultSet.getString(6);

               stageData.Y = From::getXfromY(stageData.X);

               stageData.insert();

           }

            ttsCommit;

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