通过作业队列运行 Codeunit 时出现错误,即使当我手动运行该代码单元时它工作正常。错误:“Microsoft Dynamics NAV Server 尝试发出客户端回调以创建 .NET 对象:System.Data.SqlClient.SqlConnection(报告 50126 NewOrdersCust)。Microsoft Dynamics NAV Server 不支持客户端撤回。”
此代码单元运行报告并将其保存为文件夹中的 pdf 文件。
代码单位:
OnRun(VAR Rec : Record "Job Queue Entry")
IF GUIALLOWED THEN BEGIN
programm:='\\MB\Navision\ReportsMB\PDFSoftware\cpdf.exe';
//Merged PDF1
Output := '\\MB\Navision\ReportsMB\Customers.pdf';
directory:= '\\MB\Navision\ReportsMB\2019\Customers';
Filename1:='\\MB\Navision\ReportsMB\2019\Kunden_Vertrieb\CustomersOrders.pdf';
Report1.SAVEASPDF(Filename1);
END;
该报告实际上是基于一个 SQL 查询:
报告:
MyReport - OnPreDataItem()
Servername:='*.*.*.*';
DBName:='DB';
GetSQLConnection(SQLConnection,Servername,DBName);
QueryinText:='select * from [SickDays] K Order by Year DESC, Code ASC, Monat DESC ';
SQLCommand:=SQLCommand.SqlCommand(QueryinText,SQLConnection);
SQLConnection.Open();
Queryread :=SQLCommand.ExecuteReader;
MyReport - OnAfterGetRecord()
IF (Queryread.Read()) THEN
BEGIN
LoopCount+=1;
Year:= Queryread.Item(0);
KrankDays:=Queryread.Item(5);
END
ELSE
BEGIN
SQLConnection.Close();
CurrReport.BREAK;
END;
SETRANGE(Number,1, LoopCount);
MyReport - OnPostDataItem()
GetSQLConnection(VAR SQLConnection : DotNet "System.Data.SqlClient.SqlConnection";Servername : Code[20];DBName : Code[20])
SQLConnection :=
SQLConnection.SqlConnection(
STRSUBSTNO(
'Data Source=%1;Initial Catalog=%2;Integrated Security=SSPI',
Servername,DBName));