Friday 12 April 2013

AX 2009 : ODBC connection in x++


void ABC_ODBCConnection()
{

    LoginProperty                   loginProperty;
    OdbcConnection                  odbcConnection;
    Statement                       statement,updateStmt;
    ResultSet                       resultSet;
    Notes                           sql,values;
    SqlStatementExecutePermission   perm;

    IntegrationParameters   Parameters = IntegrationParameters::find();
    PaymSchedule  PaymSch; //table instance
    ;
   //Create SQL command,
  sql = "USE PwC_Sugar_DataToSugar";
  sql = "INSERT INTO PaymentDetails";
  sql +="\n"+"  (PaymId,SalesId,PaymRefernce,Accepted,AccepetedBy,PaymStatus,DateOfAction,ClearanceDate,ClearanceStatus,ClearanceAmount,Remarks,AXRecId,ProcessedByAX,Entity)";
  sql +="\nVALUES"+values+";";
 //sql +="\nGO";


    //Set the information on the ODBC.
    loginProperty = new LoginProperty();
    loginProperty.setServer(Parameters.SQLServerIPName);
    loginProperty.setDatabase(Parameters.AXToSugarDB);

     try
     {
            //TTSBEGIN;
            odbcConnection = new OdbcConnection(loginProperty);
            if(odbcConnection)
            {              
                    perm = new SqlStatementExecutePermission(sql);
                    perm.assert();
                    statement = odbcConnection.createStatement();
                    statement.executeUpdate(sql);
                    statement.close();

                    update_recordset PaymSch setting
                    CorrectPaymSchd = NoYes::No
                    where PaymSch.CorrectPaymSchd == NoYes::Yes;

                    info("Correction are made successfully.");
               
             }

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

}

No comments:

Post a Comment