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.

Connect and upload in azure blob with azure key vault using x++

 Today, I will be sharing details about file upload in azure blob using azure vault that includes pre requisite and code snippet used to it....