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 .

  • Community Member Profile Picture
    on at
    RE: Batch job -DB connection code is not working

    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

  • Martin Dráb Profile Picture
    231,758 Most Valuable Professional on at
    RE: Batch job -DB connection code is not working

    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?

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Batch job -DB connection code is not working

    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/.../

  • Community Member Profile Picture
    on at
    RE: Batch job -DB connection code is not working

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

  • Community Member Profile Picture
    on at
    RE: Batch job -DB connection code is not working

    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();

    }

  • Martin Dráb Profile Picture
    231,758 Most Valuable Professional on at
    RE: Batch job -DB connection code is not working

    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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,758 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans