Stored Procedure Does Not Work

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Stored Procedure Does Not Work

    I am trying to run the following code against a MSSQL 2k SP4 DB. When I run
    the procedure in query analyizer it works fine. However when I use the
    following code, CF throws back "Error Executing Database Query" when in
    debugging mode. Which of course tells me little to nothing. So my question is
    does anyone see anything wrong with this block of code?

    <cfoutput>
    <cfset Parent=0>
    <cfstoredproc procedure="SpotsyFindLastInherit" datasource="CMS300DB">
    <cfprocparam cfsqltype="cf_sql_integer" type="in"
    dbvarname="@CurrentFolderID" value="#GetContent.folder_id#">
    <cfprocparam cfsqltype="cf_sql_integer" type="out" dbvarname="@ParentID"
    variable="Parent">
    </cfstoredproc>
    #Parent#
    </cfoutput>

    Robert10 Guest

  2. Similar Questions and Discussions

    1. stored procedure help
      Hi all! I am in need of writing a few stored procedures. The first one is to create a stored procedure to recover a database from backup and the...
    2. Using a stored procedure
      I am trying to pass a ProdID to a stored procedure, but I get an error: Error Executing Database Query. Procedure &apos;PriceBreak&apos; expects...
    3. help with a stored procedure
      I am new to postgres stored procedures and would like a little help. My function basically takes 2 arguments and inserts data into a table from a...
    4. Stored procedure from stored procedure
      Is it possible to create a stored procedure from a stored procedure? When I attempt this inanity, it doesn't blow up until syntax error at the...
    5. need help on a stored procedure
      I have 2 tables. table1 and table2 I do a select on table1 and join table 2 on id. I want to check newprice in table1. if it is null, I want to...
  3. #2

    Default Re: Stored Procedure Does Not Work

    Are your CFPROCPARAMs in the same order, datatype, and number as the parameters
    in your stored procedure? The dbvarname attribute is deprecated and does
    absolutely nothing, so you can't use it to "match up" your parameters.

    Phil

    paross1 Guest

  4. #3

    Default Re: Stored Procedure Does Not Work

    Yep, the params are listed in the same order they are in the procedure code. Both params are type integer, and there is one input param, and one output param.

    It has me baffled.
    Robert10 Guest

  5. #4

    Default Re: Stored Procedure Does Not Work

    Wouldn't this work better?

    <cfset Parent=0>
    <cfstoredproc procedure="SpotsyFindLastInherit" datasource="CMS300DB">
    <cfprocparam cfsqltype="cf_sql_integer" type="in" dbvarname="@CurrentFolderID"
    value="#GetContent.folder_id#">
    <cfprocparam cfsqltype="cf_sql_integer" type="out" dbvarname="@ParentID"
    variable="Parent">
    </cfstoredproc>

    <cfoutput>
    #Parent#
    </cfoutput>

    Phil


    paross1 Guest

  6. #5

    Default Re: Stored Procedure Does Not Work

    From a best practices view point yes.

    I tried that anyway on a "oh what the hell" guess... no dice. Same problem.

    Now I did notice that it complains about this line:
    <cfprocparam cfsqltype="cf_sql_integer" type="out" variable="Parent">

    or at least that is the line number being referenced in the debugging output.

    Robert10 Guest

  7. #6

    Default Re: Stored Procedure Does Not Work

    You need to attach the FULL, EXACT error message.
    It would be good to attach the SP source too.

    Without seeing the omitted details, the most common causes are that (1) order
    was scrambled as Paross said, (2) Your CF datasource does not have all the
    permission(s) it needs for the SP, (3) Input variable mis-set or SP output
    variable mis-set.


    MikerRoo Guest

  8. #7

    Default Re: Stored Procedure Does Not Work

    The CF Error in debugging mode:

    Exceptions

    16:28:04.004 - Database Exception - in MySecretTemplate.cfm : line 33
    Error Executing Database Query.

    Data source permissions:
    Select
    Insert
    Update
    Delete
    Stored Procedures

    Sp Source is as follows:

    CREATE PROCEDURE SpotsyFindLastInherit
    @CurrentFolderId integer,
    @ParentID integer output
    AS
    BEGIN
    SET NOCOUNT ON
    DECLARE @parent integer
    Declare @inheritpermissions integer
    SET @CurrentFolderID=380

    Select @inheritpermissions=inherit_permissions, @parent=parent_id
    FROm content_folder_tbl
    where folder_id=@CurrentFolderID

    WHILE @InheritPermissions <> 0
    BEGIN
    SELECT @parent = parent_id, @InheritPermissions=inherit_permissions
    FROM content_folder_tbl
    WHERE folder_id=@CurrentFolderId
    if @Inheritpermissions = 0
    SET @parent = @CurrentFolderID
    else
    SET @CurrentFolderId = @parent
    END
    SET @ParentID = @parent
    END


    GO



    Robert10 Guest

  9. #8

    Default Re: Stored Procedure Does Not Work

    Replace the Stored procedure with the attached source.

    Also, that is not the full error message -- which includes generated SQL, etc.
    Do you have all error reporting options and robust exception handling turned
    on in the CF administrator?

    The permissions you need to check are in the SQL Enterprise manager...
    Does the SQL user that you are using for CF have datareader and datawriter
    access to all tables affected by the SP.
    The SQL user must also have execute permission on SpotsyFindLastInherit.

    Finally, is the DB owner anything other than "dbo" (standard) or is their more
    than one DB with SpotsyFindLastInherit or content_folder_tbl?



    ALTER PROCEDURE SpotsyFindLastInherit
    @CurrentFolderId integer,
    @ParentID integer output
    AS
    BEGIN
    SET NOCOUNT ON
    DECLARE
    @parent integer,
    @inheritpermissions integer

    SET @parent = 0 -- Initialize!
    SET @inheritpermissions = 0
    SET @CurrentFolderID = 380 -- Suspicious!


    Select @inheritpermissions=inherit_permissions, @parent=parent_id
    FROM content_folder_tbl
    where folder_id=@CurrentFolderID

    WHILE @InheritPermissions <> 0
    BEGIN
    SELECT @parent = parent_id, @InheritPermissions=inherit_permissions
    FROM content_folder_tbl
    WHERE folder_id=@CurrentFolderId

    IF (@Inheritpermissions = 0 OR @Inheritpermissions IS NULL)
    BEGIN
    SET @parent = @CurrentFolderID
    SET @Inheritpermissions = 0
    END
    ELSE
    SET @CurrentFolderId = @parent
    END

    SET @ParentID = @parent
    IF @ParentID IS NULL
    SET @ParentID = 0
    END

    GO

    MikerRoo Guest

  10. #9

    Default Re: Stored Procedure Does Not Work

    I have all of the debugging options enabled. And that is the only thing it is
    giving me, besides the stuff that ran previous to it.

    Which I find odd as well that it did not give me the SQL code, just a generic
    error message.

    All permissions in the DB are correct, and there is only one table and one
    procedure with those names, and the owner is dbo.

    I did noticed that one line where I manually set the FolderID to 380... that
    was something I forgot to remove from testing. I removed it, and still had the
    same result.

    I tried your code as well with the same result. The additional checking for
    null is not needed as null is not allowed, but good idea to throw it in.

    I am going to try restarting the CF services tonight and see if that fixes it
    (perhaps there is some kind of CF memory problem?!), I've seen it fix wierd DB
    problems before, I just figured I was doing something wrong with my CF code.

    Robert10 Guest

  11. #10

    Default Re: Stored Procedure Does Not Work

    The addition null checking is needed -- depending on your DB and connection
    options -- even if the column does not allow nulls.

    Anyway, something is missing from this picture but a CF restart never hurts.

    Also clear the cache in CF administrator.


    MikerRoo Guest

  12. #11

    Default Re: Stored Procedure Does Not Work

    The reboot did the trick, I also now see the generated code when in debugging mode.

    Not sure what the initial problem was, but it seems to be fixed now.

    Thanks for all the help.
    Robert10 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139