Running report from Task/Job Scheduler

kuhi
Member Posts: 18
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 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;
0
Answers
-
See if this helps by any chance - https://rockwithnav.wordpress.com/2016/02/15/call-stored-procedure-from-dynamics-nav-dotnet-variable/Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions