Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 175888

failed to connect to external sql server database from ax 2012

$
0
0

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

2- [Microsoft][ODBC SQL Server Driver][SQL Server]Login 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


Viewing all articles
Browse latest Browse all 175888

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>