Showing posts with label ODBC Connection using Inbound and outbound in Ax 2012. Show all posts
Showing posts with label ODBC Connection using Inbound and outbound in Ax 2012. Show all posts

Monday, 8 February 2016

ODBC Connection using Inbound and outbound in Ax 2012

First we have to Establish ODBC Connection

  • Open Search > Administrative Tools in Ur PC
  • Select ODBC 64 or ODBC 32
  • A Prompt Will Appear as

  • Click on Add



  • Create New Data Base 
  • Check Newly Created  Data Base are added to ODBC or not

                              Inbound
static void ODBCCONNECTION_Inbound(Args _args)
{
    LoginProperty                       loginproperty;
    OdbcConnection                      odbcconnection;
    Statement                           statement;
    ResultSet                           resultset;
    str                                 sql,criteria;
    SqlStatementExecutePermission       perm;
    Custtable                           custtable;
    ODBCTABLE                           odbctable;

    ;
    loginproperty = new loginproperty();
    loginproperty.setDSN("ODBCconnection");
    loginproperty.setDatabase("DataBaseName");

    odbcconnection = new odbcconnection(loginproperty);

    if(odbcconnection)
    {
        sql = "select * from [DataBaseName].[dbo].[ODBCCUSTTABLE]";// where custgroup<=20";
        perm= new SqlStatementExecutePermission(sql);
        perm.assert();

        statement = odbcconnection.createStatement();
        resultset = statement.executeQuery(sql);

        while(resultset.next())
        {
            odbctable.AccountNum= resultset.getstring(1);
            odbctable.CustGroup= resultset.getString(2);
            odbctable.Amount   = resultset.getstring(3);
            odbctable.insert();
           
        }
        resultset.close();
        statement.close();

       info("Data Imported");
    }
    else
    {
        error("Failed to logon to the Database through ODBC");
    }
}

                                                 Outbound
static void ODBCCONNECTION_Outbound(Args _args)
{

    LoginProperty                       loginproperty;
    OdbcConnection                      odbcconnection;
    Statement                           statement;
    ResultSet                           resultset;
    Notes                               sql,values;
    SqlStatementExecutePermission       perm;
    ODBCTABLE                           odbctable;
    ;

 
    //Set the information on the ODBC.
    loginProperty = new LoginProperty();
    loginProperty.setServer("ServerName");
    loginProperty.setDatabase("DataBaseName");

     try
     {
            odbcConnection = new OdbcConnection(loginProperty);
            if(odbcConnection)
            {
                       select ODBCTABLE;
                  sql = "USE ODBCConnection";
                  sql = "INSERT INTO ODBCCUSTTABLE";
                  sql +="\n"+"  (AccountNum,CustGroup,Amount)";
                 // sql +="\nVALUES("+odbctable.accountNum+','+odbctable.CustGroup+','+odbctable.Amount+");";
                //sql+= "select (AccountNum,CustGroup,Amount) from odbctable")";
                sql += "\n"+"select AccountNum,CustGroup,Amount from ODBCTABLE;" ;
               
                    perm = new SqlStatementExecutePermission(sql);
                   perm.assert();
                    statement = odbcConnection.createStatement();
                    statement.executeUpdate(sql);
                    statement.close();
                    //update_recordset odbctable setting
                    //CustGroup = enum2str(NoYes::No)
                    //where odbctable.CustGroup ==enum2str(NoYes::Yes);
                    info("RecordS Inserted successfully.");
             }

     }
     Catch(Exception::Error)
      {
         ttsabort;
         error("Error Occured while Payment Schedule Processing");
      }

}