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:
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:
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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…