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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Error in connection from AX job to another SQL Server

(0) ShareShare
ReportReport
Posted on by

Hi ,

Error in sql connection from testing job in ax 2012 r3

sql1.png

Job code is

// X++, Main method in a class.
static public void Main(Args _args)
{
    LoginProperty loginProperty;
    OdbcConnection odbcConnection;
    Statement statement;
    ResultSet resultSet;
    str sql, criteria;
    SqlStatementExecutePermission perm;
    ;

    // Set the information on the ODBC.
    loginProperty = new LoginProperty();
    loginProperty.setDSN("sccm");
    loginProperty.setDatabase("ReportServer");

    //Create a connection to external database.
    odbcConnection = new OdbcConnection(loginProperty);

    if (odbcConnection)
    {
        // Set the select statement to the string variable
        sql = 'SELECT * from Users';


        //Assert permission for executing the sql string.
        perm = new SqlStatementExecutePermission(sql);
        perm.assert();

        //Prepare the sql statement.
        statement = odbcConnection.createStatement();
        resultSet = statement.executeQuery(sql);

        //Cause the sql statement to run,
        //then loop through each row in the result.
        while (resultSet.next())
        {
            //It is not possible to get field 3 and then 1.
            //Always get fields in numerical order, such as 1 then 2 the 3 etc.
            print resultSet.getString(1);
            print resultSet.getString(3);
        }

        //Close the connection.
        resultSet.close();
        statement.close();
    }
    else
    {
        error("Failed to log on to the database through ODBC.");
    }
}


before it created System DSN as next pic
sql2.png

the user can connect to sql server on local sql server without problems and can access to database
Any help


*This post is locked for comments

I have the same question (0)
  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    You need to set up the DSN matching the architecture as the error message suggests. The AX client is a 32-bit executable and jobs are client-bound, so use a 32-bit DSN instead of the 64-bit one (that is not indicated in the app since that is the default).

    Alternatively create a class that runs on server side, and your DSN will work if you call that class from your job instead.

  • Verified answer
    Community Member Profile Picture
    on at

    the probelm resolved after create USER DSN

    but now there is an issue

    how can create instant job or task in ax that takes the new change in another sql server table and add these new changes to ax table without duplicate the records

    first i tried this code to test connection between ax and another sql

           while (resultSet.next())

           {

               table1.First =resultSet.getString(1);

               table1.Last =resultSet.getString(2);

               table1.insert();

           }

    and the records added to ax table

    Any help

  • Vilmos Kintera Profile Picture
    46,149 on at

    That would be a new question for a new topic, do not change the topics of threads please. If your original issue is resolved, please mark helpful answers to close the thread next to the posts.

  • Community Member Profile Picture
    on at

    thank you

    you are right

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 26

#2
imran ul haq Profile Picture

imran ul haq 8

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 4 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans