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 :
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

I have the same question (0)
  • 365 financial Profile Picture
    on at

    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

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans