Skip to main content

developerWorks >  Information Management  >  Forums  >  IBM DB2 Express Forum  >  developerWorks

No authorized routine...    Point your RSS reader here for a feed of the latest messages in this thread


     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
This question is answered.

Permlink Replies: 5 - Pages: 1 - Last Post: Nov 6, 2009 2:40 PM Last Post By: ocgstyles Threads: [ Previous | Next ]
DB2Newbie_VB.NET

Posts: 11
Registered: Nov 05, 2009 08:43:17 AM
No authorized routine...
Posted: Nov 05, 2009 05:52:57 PM
 
Click to report abuse...   Click to reply to this thread Reply
Attachment DB2 STORED PROC (1.8 KB)
Tried to post my problem here kept getting Disallowed Content detected. So I've attached a full description please have a look

What am I doing wrong
Why does it work in Data Studio, half works in Control Centre and NOT work at all in the .NET subroutine.

Please help

Valued Contributor SDas

Posts: 239
Registered: Jul 23, 2008 01:24:04 PM
Re: No authorized routine...
Posted: Nov 05, 2009 06:47:18 PM   in response to: DB2Newbie_VB.NET in response to: DB2Newbie_VB.NET's post
 
Click to report abuse...   Click to reply to this thread Reply
DB2Newbie_VB.NET, First, the reason for the 'disallowed content' is the triple x in you post.

The error message you are getting is either the Stored Procedure does not exist or the parameters are not the same as the one defined.

Try running the query to get the RoutineSchema name:

SELECT ROUTINESCHEMA, ROUTINENAME
FROM SYSCAT.ROUTINES
WHERE ROUTINENAME = 'SP_GETDBSIZE_INFO'


You can also run this query to get the Parameter data types:

SELECT ROUTINENAME,PARMNAME, ORDINAL ,TYPENAME, LENGTH, SCALE
FROM SYSCAT.ROUTINEPARMS
WHERE ROUTINENAME = 'SP_GETDBSIZE_INFO'
ORDER BY ORDINAL


Next try running the CALL with the RoutineSchema name added to the Stored Procedure name:

CALL RoutineSchema.SP_GETDBSIZE_INFO(?,?,?,0)

Hopefully, this is all you need to get your Stored Procedure to run.
DB2Newbie_VB.NET

Posts: 11
Registered: Nov 05, 2009 08:43:17 AM
Re: No authorized routine...
Posted: Nov 06, 2009 09:13:45 AM   in response to: SDas in response to: SDas's post
 
Click to report abuse...   Click to reply to this thread Reply
Hello thanks for your initial reply. Let me update you on what i've done using Control Centre. I executed the

SELECT ROUTINESCHEMA, ROUTINENAME
FROM SYSCAT.ROUTINES
WHERE ROUTINENAME = 'SP_GETDBSIZE_INFO'

and the routine was present. I then did (using control centre)

SELECT ROUTINENAME,PARMNAME, ORDINAL ,TYPENAME, LENGTH, SCALE
FROM SYSCAT.ROUTINEPARMS
WHERE ROUTINENAME = 'SP_GETDBSIZE_INFO'
ORDER BY ORDINAL

and got the following result

ROUTINENAME PARMNAME ORDINAL TYPENAME LENGTH SCALE




--------
SPGET_DBSIZE_INFO SQLSTATE_OUT 1 CHARACTER 5 0
SPGET_DBSIZE_INFO SQLCODE_OUT 2 INTEGER 4 0

So I think it exists

When I executed CALL SPGET_DBSIZE_INFO I got the error no authorised routine.....

I went back to Data studio 2.2, executed the stored procedure sucessfully then opened the stored procedure to have a look inside. Here it is

CREATE PROCEDURE SPGET_DBSIZE_INFO ( OUT SQLSTATE_OUT CHAR(5),
OUT SQLCODE_OUT INTEGER )
DYNAMIC RESULT SETS 1

    • SQL Stored Procedure
-- SQLSTATE_OUT
-- SQLCODE_OUT
P1: BEGIN
-- Declare variables
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE SQLCODE INT DEFAULT 0;

-- Declare cursor
DECLARE cursor1 CURSOR WITH RETURN FOR
SELECT *
FROM SYSTOOLS.STMG_DBSIZE_INFO;

-- Declare handler
DECLARE EXIT HANDLER FOR SQLEXCEPTION
SELECT SQLSTATE, SQLCODE INTO SQLSTATE_OUT, SQLCODE_OUT
FROM SYSIBM.SYSDUMMY1;

-- Cursor left open for client application
OPEN cursor1;
SET SQLSTATE_OUT = SQLSTATE;
SET SQLCODE_OUT = SQLCODE;
END P1

Now i created this stored procedure using the wizard for creating stored procedures in Data Studio.

Just for fun i decided to create another stored procedure, exactly the same as the first called SPGET_DBSIZE_INFO1, using the wizard, this time i only selected SQL Exception handling. It generated the following

CREATE PROCEDURE SPGET_DBSIZE_INFO1 ( )
DYNAMIC RESULT SETS 1

    • SQL Stored Procedure
P1: BEGIN
-- Declare cursor
DECLARE cursor1 CURSOR WITH RETURN FOR
SELECT *
FROM SYSTOOLS.STMG_DBSIZE_INFO;

-- Cursor left open for client application
OPEN cursor1;
END P1

I went back to control centre and executed this new stored procedure SPGET_DBSIZE_INFO1 and IT WORKED...you can imagine my excitement, which quickly turned to puzzelment.
Why does SPGET_DBSIZE_INFO1 work and SPGET_DBSIZE_INFO not work in Control Centre, while both work in Data Studio. What specifcally do i need to type in Control Center to get my first stored procedure SPGET_DBSIZE_INFO to work

I've tried to give as much information as i know. If you have any answers please help

Valued Contributor SDas

Posts: 239
Registered: Jul 23, 2008 01:24:04 PM
Re: No authorized routine...
Posted: Nov 06, 2009 09:45:34 AM   in response to: DB2Newbie_VB.NET in response to: DB2Newbie_VB.NET's post
 
Click to report abuse...   Click to reply to this thread Reply
DB2Newbie_VB.NET, before I continue, I will just state I am a DBA and not an application developer.

According to the output from RoutineParms, the Stored Procedure only has 2 parameters. But in you call example, your original CALL example you were using 5 parameters:

CALL get_dbsize_info(?,?,?,0)

Try it with just 2:

CALL get_dbsize_info(?,?)

And see what happens.

By the way, I have no idea what this Select is getting you:

    • Declare handler
DECLARE EXIT HANDLER FOR SQLEXCEPTION
SELECT SQLSTATE, SQLCODE INTO SQLSTATE_OUT, SQLCODE_OUT
FROM SYSIBM.SYSDUMMY1;

At the most, it will get an SQLSTATE and SQLCODE from the DECLARE. (remember, I am not a programmer).
DB2Newbie_VB.NET

Posts: 11
Registered: Nov 05, 2009 08:43:17 AM
Re: No authorized routine...
Posted: Nov 06, 2009 11:22:57 AM   in response to: SDas in response to: SDas's post
 
Click to report abuse...   Click to reply to this thread Reply
Simply put SDas, your a GENIUS...I did spget_dbsize_info(?,?) from in control centre and it worked, I proceded to try executing the same call from my .NET application and IT WORKED. Thank you very much

Declare handler
DECLARE EXIT HANDLER FOR SQLEXCEPTION
SELECT SQLSTATE, SQLCODE INTO SQLSTATE_OUT, SQLCODE_OUT
FROM SYSIBM.SYSDUMMY1;

I have NO CLUE what the above lines do. I just picked up DB2 the other day coz I'm trying to do a proof of concept that DB2 is worth a look....but that code is generated using Data Studio 2.2 when creating a stored procedure using wizard.

Thank you for your help.
Valued Contributor ocgstyles

Posts: 535
Registered: Dec 27, 2005 01:10:09 AM
Re: No authorized routine...
Posted: Nov 06, 2009 02:40:46 PM   in response to: DB2Newbie_VB.NET in response to: DB2Newbie_VB.NET's post
 
Click to report abuse...   Click to reply to this thread Reply
In reference to this section:

DECLARE EXIT HANDLER FOR SQLEXCEPTION
SELECT SQLSTATE, SQLCODE INTO SQLSTATE_OUT, SQLCODE_OUT
FROM SYSIBM.SYSDUMMY1;

You are declaring a "handler" that will run when a SQLEXCEPTION occurs. This is an EXIT handler, so, the body of the handler will run, then the procedure will exit and return to the caller.

So now that we know what this block is for, what is the body of the handler doing?

Earlier in the procedure you had declared 2 variables:
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE SQLCODE INT DEFAULT 0;

You MUST declare these variables in your code if you want DB2 to populate them. So, when an exception occurs, DB2 will populate SQLSTATE and SQLCODE for you, simply because you declared variables. What the body of the exit handler is doing is setting the procedure output parameters to these values. Hence, you can see those values outside the procedure after it runs.

HTH

  • Keith
 Tags
Help

Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular type of content or application that you're viewing.

My tags shows your tags for this particular type of content or application that you're viewing.

 

MoreLess 


Point your RSS reader here for a feed of the latest messages in all forums