Re: SP - output parameter not coming back
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Wed, 15 Jun 2005 06:45:01 -0400
Axel wrote:
> Hi
>
> I have a stored procedure that returns a recordset with search
> results. I also want it to return the number of records in an output
> parameter. The problem is it does not seem to transmit anything to
> the server page - what could be wrong? (just for test purposes I
> tried to assign a fixed value, or change the order of parameters but
> it is simply not read) - instead it seems to assign Null no matter
> what I tried. The recordset is returned as expected though. I changed
> the cursor type to client side in order to get the correct count.
>
> Also is there any way I can test output params in SQL Query Analyzer?
http://groups-beta.google.com/group/microsoft.public.inetserver.asp.general/msg/2c935bd7c531d82b
>
> thanks in advance
> Axel
>
> ---------- Code follows --------
>
> Stored Proc code:
> CREATE PROCEDURE dbo.spFindProducts
> @mycount integer OUTPUT,
> @whereString varchar (1000)
> AS
>
> --SET NOCOUNT ON
Why do you have this commented out? You need to have this turned on to avoid
having your procedure return extra resultsets containing the number of
records affected by each statement. This statement being turned on will NOT
affect the contents of @@ROWCOUNT
<snip>
>
> Set CmdSP = Server.CreateObject("ADODB.Command")
> '-- Make an ODBC connection to the (local) SQL server,
>
Don't use ODBC:
http://www.aspfaq.com/show.asp?id=2126
>
> Dim rs
> Dim lRecCount
> Set rs = Server.CreateObject("ADODB.Recordset")
>
> CmdSP.ActiveConnection = Application("cnn")
If you are storing a Connection object in Application, that is a bad idea:
http://www.aspfaq.com/show.asp?id=2053
If Application("cnn") is a connection string, then you are still using a bad
practice: ALWAYS use an explicit Connection object so as not to disable
connsection/session pooliing:
set cn=createobject(adodb.connection")
cn.open Application("cnn")
Set CmdSP.ActiveConnection = cn
> CmdSP.CommandText = "spFindProducts"
> CmdSP.CommandType = 4 ' adCmdStoredProc
>
You forgot to append the return parameter. Even though you are not using it,
it must be the first parameter appended to the collection.
>
> ' CmdSP.Parameters.Append _
> ' CmdSP.CreateParameter("@mycount", adInteger, adParamOutput)
> CmdSP.Parameters.Append _
> CmdSP.CreateParameter("@mycount", 3, 2)
>
> ' CmdSP.Parameters.Append
> CmdSP.CreateParameter("@whereString",adVarChar=200, 1, len(sWhere),
> sWhere) ' adVarChar, adParaminput, ...)
> CmdSP.Parameters.Append _
> CmdSP.CreateParameter("@whereString", adVarChar, _
> adParamInput, len(sWhere), sWhere)
>
>
> ' RECORDSET OBJECT
> ' Open recordset (from stored Proc)
> Dim dummyArr
> Set rs = CmdSP.Execute( ) ' RecordCount can not be used
> ' set cursor type to clientside for this to work? =>
> ' @mycount: THIS PARAMETER EXISTS, BUT IT HAS NO VALUE FOR SOME
> ' UNKNOWN REASON!
> ' tried: changing param order
> ' assigning constant in SP
> ' not executing & filling the recordset
> ' seems to always pass back empty
> ' append identifier ".Value"
> lRecCount = CmdSP.Parameters("@mycount").Value
>
>
> ' in order to use recordcount we need to
> ' set the cursortype to something different than forward only
> ' then movelast - get RecordCount and MoveFirst...
>
Output and Return parameter values are not sent until all the resultsets
generated by the procedure are sent to the client. This means that you must:
1. When using forward-only cursors, close your recordset before attempting
to read the output and return parameters
2. When using a client-side cursor, the entire static resultset is sent when
the recordset is opened, so the output and return parameters are immediately
sent.
You may be interested in my free stored procedure code generator available
here:
http://www.thrasherwebdesign.com/index.asp?pi=links&hp=links.asp&c=&a=clear
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
.
- Follow-Ups:
- Re: SP - output parameter not coming back
- From: Axel
- Re: SP - output parameter not coming back
- Prev by Date: How to dereferencing ADODB on server?
- Next by Date: Re: How to dereferencing ADODB on server?
- Previous by thread: How to dereferencing ADODB on server?
- Next by thread: Re: SP - output parameter not coming back
- Index(es):
Relevant Pages
|
Loading