Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

microsoft dynamics - Running report from Task/Job Scheduler

I'm trying to run a report that execute some SQL queries in NAV 2015

If I run the report manually it's working perfectly, but when I set it into the Task Scheduler it give error as it has an automation that is trying to load in the client.

I've changed the CREATE parameters to (FALSE, FALSE) instead of (FALSE, TRUE) so it runs in Server instead of Client, but when I try to compile it will give this error:

enter image description here

Translation: Cannot create an automation object "sqlConnection" in NAV Server. You must create it in Client.

But if I create it in client CREATE(FALSE, TRUE) it will give error: enter image description here

Translation: NAV Server was trying to return a Client call to create an automation object. Call returns from Client are not allowed in NAV Server.

This is the code: (Looping Company table)

IF (STRPOS(LOWERCASE(Company.Name), 'prueba') = 0) AND (STRPOS(LOWERCASE(Company.Name), 'test') = 0) AND (STRPOS(LOWERCASE(Company.Name), 'uat') = 0) AND (STRPOS(LOWERCASE(Company.Name), 'prova') = 0) THEN BEGIN
  recWasteHeader.CHANGECOMPANY(Company.Name);
  IF recWasteHeader.COUNT > 0 THEN BEGIN
    recWasteLine.SETRANGE("Document Type", 4);
    recWasteLine.SETRANGE("Business Type", 2);
    recWasteLine.SETFILTER("Sub Contract No.", '<>%1', '*NUL*');
    IF recWasteLine.FINDSET THEN BEGIN
      IF ISCLEAR(sqlConnection) THEN
        CREATE(sqlConnection, FALSE, FALSE);
      sqlConnection.Open(ConnectionString);

      IF ISCLEAR(sqlCommand) THEN
        CREATE(sqlCommand, FALSE, FALSE);
      sqlCommand.ActiveConnection := sqlConnection;                      
      sqlCommand.CommandText := 'DELETE FROM [Noc Services Price] WHERE Empresa=' + q + Company.Name + q;
      sqlCommand.CommandType := 1;
      sqlCommand.Execute;

      REPEAT
        querydata := STRSUBSTNO(dataset, Company.Name, recWasteLine."Document No.", recWasteLine."Line No.", recWasteLine.Amount);
        sqlCommand.CommandText := 'INSERT INTO [Noc Services Price] (Empresa, Contracte, [Linea contracte], [PREU ACTUAL]) VALUES ( ' + querydata + ');';
        sqlCommand.Execute;
      UNTIL recWasteLine.NEXT = 0;

      sqlConnection.Close;      
    END;
  END;
END;

I also can't find the dotnet System.Data.SqlClient

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...