As part of Customer requirements , sometimes we need to connect to DataBase otherthan Axapta DataBase. So let us explore how it can be done with X++ code.
In Ax using ODBCConnection and LoginProp its possible to connect to Database on remote server, as illustrated in the following example.I tried the following code on MSSQL Server.
static void test_ODBCConnection(Args _args)
{ LoginProperty loginProp;
ODBCConnection conn;
Resultset resultSet, resultSetCount;
// get record Statement statement1, statement2;
// Create SQL Statement ResultSetMetaData metaData ;
// get Record metadate like columnname. ;
// Set Server Database loginProp = new LoginProperty();
loginProp.setServer('SON15092');
loginProp.setDatabase('AdventureWorksDW');
// Create Connection and SQL Statement conn = new ODBCConnection(loginProp);
statement1 = conn.createStatement();
resultSet = statement1.executeQuery("SELECT * from DimTime");
while (resultSet.next())
{
metaData = resultSet.getMetaData();
info("Column Name :"+metaData.getColumnName(1)+" Value ="+resultSet.getString(1));
}
}Enjoy, X++!!!!!!