Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

failed to connect to external sql server database from ax 2012

Posted on by 61

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
    365 financial 61 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);

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans