Bojensen Blogs

Connecting MSSQL DataBase with X++ Code.

Sometimes we need to connect to DataBases other than the 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();
// Create Connection and SQL Statement
conn = new ODBCConnection(loginProp);
statement1 = conn.createStatement();
resultSet = statement1.executeQuery("SELECT * from DimTime");
while (
metaData = resultSet.getMetaData();
info("Column Name :"+metaData.getColumnName(1)+" Value ="+resultSet.getString(1));

Learn Dynamics Ax: Connecting MSSQL DataBase with X++ Code.

Comments are closed.