Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

failed to connect to external sql server database from ax 2012

(0) ShareShare
ReportReport
Posted on by

1- ODBC operation failed.
Unable to log on to the database.

2- [Microsoft[ODBC SQL Server Driver[SQL ServerLogin failed. The login is from an untrusted domain and cannot be used with Integrated authentication.

3- Object 'OdbcConnection' could not be created

Hi all i am trying to pull some data from external databse to ax table so i configured a DSN and the connection was successfully, i called it to x but the connection failed 

 LoginProperty                   loginProperty;
        OdbcConnection                  odbcConnection;
        Statement                       statement;
        ResultSet                       resultSet;
        str                             sql, criteria;
        SqlStatementExecutePermission   perm;
    
        MYTABLE                           MYTABLE;
        ;
    
        // Set the information on the ODBC.
        loginProperty = new LoginProperty();
        loginProperty.setDSN('DSN');
        loginProperty.setDatabase('DB');
    
        //Create a connection to external database.
        odbcConnection = new OdbcConnection(loginProperty);
    
        if (odbcConnection)
        {
            sql = 'SELECT * FROM MYTABLE ORDER BY FIELD ASC ;';
    
            //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.
                info(resultSet.getString(1));
                info(resultSet.getString(2));
                info(resultSet.getString(3));
                info(resultSet.getString(4));
               
            }
    
            //Close the connection.
            resultSet.close();
            statement.close();
        }
        else
        {
            error('Failed to log on to the database through ODBC.');
        }

So any help please

  • 365 financial Profile Picture
    on at
    RE: failed to connect to external sql server database from ax 2012

    Ok it is work now i just make some search in some resource on the the net and found that omitting this line

    loginProperty.setDSN('DSN');

    and adding these tow lines:

    ConnectionString = strfmt("DSN=%1;UID=%2;PWD=%3",'DSNName', 'sa',@'pass');

    loginProperty.setOther(ConnectionString);

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,017 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans