Thursday 20 December 2018

Create an ODBC connection in AX

Today, I will be discussing about how to create an odbc connection in AX. As we all know our system might require data from external resources for instance directly connecting with data base.
For this purpose first you need to configure ODBC connection and use odbcconnection class for creating connection with data base using X++.

Below is the code snippet.

  LoginProperty                                  loginProperty;
  OdbcConnection                              odbcConnection;
  Statement                                         statement;
  str                                                     sqlInsert;
  SqlStatementExecutePermission     permInsert;

   // Set the information on the ODBC.
   loginProperty = new LoginProperty();
   loginProperty.setDSN('DSN Name');
   loginProperty.setDatabase('Integration database name');

   odbcConnection = new OdbcConnection(loginProperty);

   if ( odbcConnection)
   {
        statement = odbcConnectionInsertHeader.createStatement();
        sqlInsert = strFmt('INSERT INTO [table_name]([field1], [field2])') + strFmt('VALUES(values1, value2)')
        permInsert  = new SqlStatementExecutePermission(sqlInsert);
        permInsert.assert();
        statement.executeUpdate(sqlInsert);
        CodeAccessPermission::revertAssert();
   }

    statement.close();

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Custom Business events Part 3 - (Activate custom business event) in D365 F&O

 In this blog we will discuss about the steps to activate a custom business in D365 F&O. As we know that business event catalog does not...