Error while running codeunit through job queue on Navision - rdlc

I have an Error while running a Codeunit through job queue, even though this code unit works fine when I run it manually.
Error:
"Microsoft Dynamics NAV Server attempted to issue a client callback to create a .NET object: System.Data.SqlClient.SqlConnection (Report 50126 NewOrdersCust). Client recalls are not supported for Microsoft Dynamics NAV Server."
This code unit runs a report and saves it as a pdf file in a folder.
CodeUnit:
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;
The report is actually based on an SQL query:
Report:
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));
This report contains the following .net variables

On the .net variables you have probably set property RunOnClient to True. You can’t do that if you want to run this report on server. Set this property to false and make sure you have needed libraries on the nav server.

Related

SQL Error -4903 when trying to connect to DB2 database

I am getting an SQL error code of -4903 when trying to connect to a DB2 database using SQC code (this is an ANSI C application so I need to use SQC for SQL queries). When I look at IBM's website to see what a -4903 means, all it says is "The length of parameter n of function name is not valid". However I have no idea which parameter or function it is referring to. I have tried looking at the SQLCA objects members, but I am unable to see them in Visual Studio 2015.
This is an ANSI C application debugging in Visual Studio 2015. I am able to connect to the same database using a DB2 command prompt (i.e, by running "db2 connect to dbname user username using password". However when I try to do this in code I get the -4903 error. I have also tried this on two different OS's, Windows 7 and Windows 10. I have colleagues who have had no trouble doing this on a Windows 7 machine.
while ((retry++ < 3)
|| (sqlca.sqlcode == -30080)
|| (sqlca.sqlcode == -900 ) )
{
EXEC SQL CONNECT TO :DBName USER :userid USING :pword;
if ((SQLCODE == 0 ) || (SQLCODE == (-1026)))
{
return(1);
}
else
{
dbLogAudit(KLCB, PLCB, KLLOGSEV(T),
"Retry DBInit/sqlca.sqlcode : %i", sqlca.sqlcode);
}
}
I expect the SQLCODE to be 0, which indicates a successful connection, and for the function to return 1 to it's caller. But instead the sqlca.sqlcode variable is -4903 (which I described above).
EDIT: I found the parameters being passed into the error message. The full error text is "The length of parameter runtime_pid of function sqlastrt_trusted is not valid".
I solved my own issue. Thanks to Mao for the help on debugging this one.
My development environment for DB2 was running version 8.1.0, which uses 162 bytes for the struct called "sqla_program_id". However, the runtime environment, which uses 292 bytes for that same struct, was version 10.5. Once I upgraded my development DB2 instance to v10.5 it worked like a charm.

Unable to access DBCONN after migration to EHP7

I want to access Unix Database from my SAP system.
I was using cl_sql_connection class to open the connection.
This class was working fine before the upgrade to EHP7.
But, now, I am unable to Access table DBCONN in any Stabdard SAP transaction (SE16, SE11...)
Following is my code, returning exception since EPH7 upgrade.
* Fetch data from the ACMM application, using db-links.
TRY.
CALL METHOD cl_sql_connection=>get_connection
EXPORTING
con_name = lw_dbcon_name
RECEIVING
con_ref = lo_sql_connection.
CATCH cx_sql_exception .
=>An exception occurred while opening SQL Connection
ENDTRY.
Is their any other way through which i can connect to other Server?
Yes, there is. You can use the (older) variant of EXEC SQL.
But before you do, check the connection using ADBC_TEST_CONNECTION in SE38.
You could also get some more details by exploring the exception object you have. Here is how I usually do it:
TRY.
EXEC SQL.
CONNECT TO 'ZUNIXDB_DBCON'
ENDEXEC.
EXEC SQL.
OPEN dbcur FOR
SELECT id FROM table
ENDEXEC.
CATCH cx_sy_native_sql_error INTO lr_cx_native_sql_error.
Now you have info like:
lr_cx_native_sql_error->get_text( )
lr_cx_native_sql_error->get_longtext( )
lr_cx_native_sql_error->sqlmsg

Initialize / activate SQL prior to GET DIAGNOSTICS

I have two service programs: mySrvPgm and myErr
mySrvPgm has a procedure which contains:
/free
...
exec sql INSERT INTO TABLE VALUES(:RECORD_FMT);
if sqlError() = *ON;
//handle error
endif;
...
/end-free
myErr has a procedure sqlError:
/free
exec sql GET DIAGNOSTICS CONDITION 1
:state = RETURNED_SQLSTATE;
...
/end-free
Background info: I am using XMLSERVICE to call the given procedure in mySrvPgm from PHP. I am not using a persistent connection. myErr is bound-by-reference via a binding directory used by mySrvPgm. Its activation is set to *IMMED, its activation group is set to *CALLER.
The problem: Assume there is an error on the INSERT statement in mySvrPgm. The first time sqlError() is called it will return SQLSTATE 00000 despite the error. All subsequent calls to sqlError() return the expected SQLSTATE.
A workaround: I added a procedure to myErr called initSQL:
/free
exec sql SET SCHEMA MYLIB;
/end-free
If I call initSQL() before the INSERT statement in mySrvPgm, sqlError() functions correctly. It doesn't have to be SET SCHEMA, it can be another GET DIAGNOSTICS statement. However, if it does not contain an executable SQL statement it does not help.
The question: I believe the myErr service program is activating properly and has the correct scope, but I am wondering if there is something more I need to do to activate the SQL part of it. Is there some way to set it up so SQL auto-initializes when the service program is activated, or do I have to execute an unneeded SQL statement in order to get it started?
There is some more background information available here.
Thank you for reading.
What version an release of the OS? Are you upto date on PTFs?
Honestly, seems to me that it's possibly a bug. Or the manual(s) need clarification.. I'd open a PMR.

Old VB6 App using ADODB throwing error when calling Oracle Stored Procedure

This has to be provider related in some way because it works fine on my dev box but doesn't work on another dev box.
Here is the error I'm getting on the non-working dev box:
ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 26
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'LISTAVAILSUBMISSIONS'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Here is the Oracle Procedure:
Procedure ListAvailSubmissions (avail_submission in out rc_avail_submission)
is
Begin
open avail_submission for
select submission_id from nais_submissions
where condition = 'ONLINE'
and status in ('ACTIVE','LOGGED')
order by submission_id desc;
Exception
When no_data_found then
v_output := utl_file.fopen (v_errdir, v_errLog, 'a');
utl_file.put_line(v_output, to_char(sysdate,'HH24:MI:SS')||'-'||'ListAvailSubmission:Sub_id: No Data Found');
utl_file.fclose(v_output);
When others then
v_error_code := sqlcode;
v_error_message := substr (sqlerrm, 1, 300);
v_output := utl_file.fopen (v_errdir, v_errLog, 'a');
utl_file.put_line(v_output, to_char(sysdate,'HH24:MI:SS')||'-'||'ListAvailSubmission:Sub_id:'|| v_error_code ||':'|| v_error_message);
utl_file.fclose(v_output);
End ListAvailSubmissions;
As you can see, the only parameter is the return parameter which is the resulting recordset
The call from VB is pretty simple.
Public Function GetTestRequests() As ADODB.Recordset
Dim rsADO As New ADODB.Recordset
Dim cmdCommand As New ADODB.Command
Set cmdCommand.ActiveConnection = cnnADO //Ive already verified the connection is good
cmdCommand.CommandText = "ListAvailSubmissions"
Set rsADO = cmdCommand.Execute(, , adCmdStoredProc)
Set GetTestRequests = rsADO
End Function
The frustrating part is the it works on one machine and not another. I'm using msdaora.1 as the provider and I've verified both machines have the same MDAC version using MS CompChecker tool. One thing I did discover is that if I switch the working machine to using OraOLEDB instead of msdaora.1, it will then throw the same error. Based on that I'm starting to think that the non-working machine is exhibiting the correct behavior and that I need to fix the code.
I have done quite a bit of research and I'm thinking it has to do with the in out parameter and trying to set an ADODB.Recordset equal to the parameter. I tried changing the parameter to out only but that didn't help, still got the same error.
Any help is appreciated, this error is driving me nuts.
I think one of the strings in your table exceeds the OLEDB string limit. This limit is defined differently for different drivers -- so you see one driver giving error and another works. This limit, I believe, can also be configured on a machine-by-machine basis, thus you have one machine working and one doesn't.
Check if any string in your result set is longer than, say, 256 characters or something really long. Then omit that record from your result set to see if it works.

SQL Server Agent 2005 job runs but no output

Essentially I have a job which runs in BIDS and as as a stand lone package and while it runs under the SQL Server Agent it doesn't complete properly (no error messages though).
The job steps are:
1) Delete all rows from table;
2) Use For each loop to fill up table from Excel spreasheets;
3) Clean up table.
I've tried this MS page (steps 1 & 2), didn't see any need to start changing from Server side security.
Also SQLServerCentral.com for this page, no resolution.
How can I get error logging or a fix?
Note I've reposted this from Server Fault as it's one of those questions that's not pure admin or programming.
I have logged in as the proxy account I'm running this under, and the job runs stand alone but complains that the Excel tables are empty?
Here's how I managed tracking "returned state" from an SSIS package called via a SQL Agent job. If we're lucky, some of this may apply to your system.
Job calls a stored procedure
Procedure builds a DTEXEC call (with a dozen or more parameters)
Procedure calls xp_cmdshell, with the call as a parameter (#Command)
SSIS package runs
"local" SSIS variable is initialized to 1
If an error is raised, SSIS "flow" passes to a step that sets that local variable to 0
In a final step, use Expressions to set SSIS property "ForceExecutionResult" to that local variable (1 = Success, 0 = Failure)
Full form of the SSIS call stores the returned value like so:
EXECUTE #ReturnValue = master.dbo.xp_cmdshell #Command
...and then it gets messy, as you can get a host of values returned from SSIS . I logged actions and activity in a DB table while going through the SSIS steps and consult that to try to work things out (which is where #Description below comes from). Here's the relevant code and comments:
-- Evaluate the DTEXEC return code
SET #Message = case
when #ReturnValue = 1 and #Description <> 'SSIS Package' then 'SSIS Package execution was stopped or interrupted before it completed'
when #ReturnValue in (0,1) then '' -- Package success or failure is logged within the package
when #ReturnValue = 3 then 'DTEXEC exit code 3, package interrupted'
when #ReturnValue in (4,5,6) then 'DTEXEC exit code ' + cast(#Returnvalue as varchar(10)) + ', package could not be run'
else 'DTEXEC exit code ' + isnull(cast(#Returnvalue as varchar(10)), '<NULL>') + ' is an unknown and unanticipated value'
end
-- Oddball case: if cmd.exe process is killed, return value is 1, but process will continue anyway
-- and could finish 100% succesfully... and #ReturnValue will equal 1. If you can figure out how,
-- write a check for this in here.
That last references the "what if, while SSIS is running, some admin joker kills the CMD session (from, say, taskmanager) because the process is running too long" situation. We've never had it happen--that I know of--but they were uber-paranoid when I was writing this so I had to look into it...
Why not use logging built into SSIS? We send our logs toa database table and then parse them out to another table in amore user friendly format and can see every step of everypackage that was run. And every error.
I did fix this eventually, thanks for the suggestions.
Basically I logged into Windows with the proxy user account I was running and started to see errors like:
"The For each file enumerator is empty"
I copied the project files across and started testing, it turned out that I'd still left a file path (N:/) in the properties of the For Each loop box, although I'd changed the connection properties. Easier once you've got error conditions to work with. I also had to recreate the variable mapping.
No wonder people just recreate the whole package.
Now fixed and working!