web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Batch job -DB connection code is not working

(0) ShareShare
ReportReport
Posted on by

Dear all ,

  We are doing an integration ,we are getting data from MySql(PHP) to AX. for that  wrote one job in ax 2012 ,please find the code below . The Same job is working is working fine ,but when i add the same code to class for Batch job  .batch job is not working  (the following error is throwing : value cannot be null).

 

 pls do needful

Thanks in advance .

I have the same question (0)
  • Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at

    Unfortunately we don't see the code. You also forgot to mention which line of code is throwing the error.

    By the way, you're comparing two very different cases - code running by different applications (AOS vs. AX client), using different processor architecture (64 bit / 32 bit), on different computers, by different accounts, by different runtime (CLR vs. X++) and so on. If you don't do more granular tests, you can't be sure what is causing your problem. For example, try running your code in X++ on server. This will tell you that your code can run on AOS - it has the right DLLs, it can run in 64-bit environment and so on. Then run it interactively in CIL. If it doesn't work, try rebuilding CIL.

    Only when these cases works, run it as a batch job. But if they don't work, you'll know that your problem isn't related to batches at all and you won't have to complicate your live by debugging batch jobs.

  • Community Member Profile Picture
    on at

    LoginProperty       loginProperty;

    OdbcConnection      odbcConnection;

    Statement           statementOption, sqlUpdateOption;

    ResultSet           resultSet;

    str                 sqlOption, sqlUpdate,updateStmt;

    Set                 permissionSet;

    str                 id;

    DFRouteCardJournal   routeCardJournal;

    loginProperty = new LoginProperty();

    //loginProperty.setServer('.');

    //loginProperty.setDatabase("TestDB");

        loginProperty.setDSN("******");

        loginProperty.setDatabase("****");

    //Create a connection to external database.

    odbcConnection = new OdbcConnection(loginProperty);

    //sqloption = "SELECT * FROM Options";

    sqloption = " SELECT ph.Production,rl.OperationNo,rl.Good_quantity,rl.Hours/3600 AS hours,ph.Journal,rl.Resource,rl.id FROM master_post_head ph JOIN master_post_route_line rl ON ph.id=rl.ref_id and rl.erp_status='unprocess'";

    //sqlupdate = "UPDATE Options SET Completed = 1";

    sqlupdate = "update  master_post_route_line set erp_status = 'processed' " ;

    permissionSet = new Set(Types::Class);

    permissionSet.add(new SqlStatementExecutePermission(sqloption));

    permissionSet.add(new SqlStatementExecutePermission(sqlupdate));

    CodeAccessPermission::assertMultiple(permissionSet);

    //Prepare the sql statement.

    statementoption = odbcConnection.createStatement();

    resultSet = statementoption.executeQuery(sqloption);

    while (resultSet.next())

    {

                  routeCardJournal.clear();

                  routeCardJournal.ProdId =  resultSet.getString(1);

                  routeCardJournal.Oprnum =   resultSet.getInt(2);//str2int(resultSet.getString(2));

                  routeCardJournal.QtyGood =  resultSet.getReal(3);//str2int(resultSet.getString(3));

                  routeCardJournal.hours   =  resultSet.getReal(4);

                  routeCardJournal.DFJournalId =  resultSet.getString(5);

                  routeCardJournal.WrkCtrId =  resultSet.getString(6);

                  routeCardJournal.JournalStatus = SiegerJournalStatus::Unprocessed;

                  routeCardJournal.DFId          = resultSet.getInt(7);

                  routeCardJournal.insert();

                  id = resultSet.getString(7);

       sqlupdateoption = odbcConnection.createStatement();

       sqlupdate= strFmt("update  master_post_route_line set erp_status =  '%2' where id = '%1'", id,'processed');

       sqlupdateoption.executeUpdate(sqlupdate);

    }

    resultSet.close();

    statementoption.close();

    }

  • Community Member Profile Picture
    on at

    Need help on how to get the data from another database in batch job

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Have you checked if the AOS account has read/write privileges on the external DB? The fact that a job works well suggests that your user account has access to the external DB.

    Alternatively, you could use DIXF to get data from another database using ODBC as source. You can follow this blog -

    axarif.wordpress.com/.../

  • Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at

    I still don't see any description of your problem. Use the debugger if you have no idea where your code is failing.

    Please use Insert > Insert Code (in the rich formatting view) to paste source code; it'll be much easier to read.

    What I see from your code is that you're using ODBC. Did you create a DSN on the machine with AOS?

  • Community Member Profile Picture
    on at

    Martin ,thanks

    That issue is done ,actually i used the sysoperationServicecontroller class  for batch ,   but that is the issue.

    once i changed my code with extends RunBaseBatch,   issues are solved. (ussing 64 bit and ODBC).

    thanks to all

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans