Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 sproc returning rows to query analyzer but not VB

Author  Topic 

sumo
Starting Member

45 Posts

Posted - 2002-01-29 : 12:25:29
I have a stored procedure that uses the SQL Server technique for paging. It creates a temporary table of all of the results and then queries that temp table to filter out the amount of rows specified on the correct page. The sproc returns rows when run in query analyzer, but if I try to get a recordset in a VB6 component (w/MDAC 2.6 SP1), I get an ADO error stating that the recordset is closed.

We have experienced this problem in the past and have found no real fix for it. Is there a bug somewhere? I can guarantee that my ADO code and my sproc code is correct.

The sproc is below. It has been edited to remove transactions and error checking. It's down to the basic function of the sproc.

CREATE PROCEDURE KeywordSearchResults_Gen_Vend

/*
Name: KeywordSearchResults_Gen_Vend
Description: This sproc returns a list of parts based on generic description chosen and current page. It sorts by Vendor, Part Number ASCENDING.
Author: Michael Sumerano
Date: 01/25/2002
*/

@BlanketMargin decimal(6,3),
@Warehouse int,
@AltWarehouse int,
@CustNo int,
@GenKey int,
@page int,
@size int,
@pagecount int OUTPUT

AS

declare @start int, @end int

--Calculate the starting Row
SET @Start = (((@Page - 1) * @Size) + 1)

--Calculate the ending Row
SET @End = (@Start + @Size - 1)

--Create temporary table to store all results from search
CREATE TABLE #FullResults
(
Row int IDENTITY(1,1) PRIMARY KEY,
InvKey int,
VendNum char(3),
VendorName char(12),
PartNum char(25),
[Description] char(25),
RetailPrice money,
JobberPrice money,
CorePrice money,
FederalExciseTax money,
PriceCode bit,
OnHand int,
AltInventory int,
SpecialOrder bit,
Reference bit
)

--Insert all results from search
INSERT INTO #FullResults
SELECT DISTINCT
Inv.InvKey,
inv.VendNum,
Ven.VendorName,
Inv.PartNum,
Inv.[Description],
jobberprice / (1 - ISNULL((markup), @BlanketMargin) / 100) AS RetailPrice,
Inv.jobberprice,
Inv.corePrice,
Inv.federalExciseTax,
Inv.PriceCode,
boh.onHand,
alt.onHand as AltInventory,
Inv.SpecialOrder,
NULLIF(ISNUMERIC(ref.refkey), 0) as Reference
FROM
dbo.Inventory inv
INNER JOIN
dbo.Vendor ven ON Inv.VenKey = Ven.VenKey
LEFT OUTER JOIN
dbo.reference ref ON inv.invkey = ref.invkey
LEFT OUTER JOIN
dbo.OnHand boh ON Inv.InvKey = boh.InvKey and boh.warehouse = 1
LEFT OUTER JOIN
dbo.OnHand alt ON Inv.InvKey = alt.InvKey and alt.warehouse = 1
LEFT OUTER JOIN
dbo.Markup mu ON mu.vendornum = ven.vendornum and mu.CustomerNumber = 9400
WHERE
inv.invkey in (select DISTINCT invkey from dbo.accessory where gennum = @GenKey)
ORDER BY
ven.vendorname, inv.partnum

--Calculate the page count
set @pagecount = CEILING(@@ROWCOUNT / cast(@size as numeric(5,3)))

--Select the search results based on the current page
SELECT
InvKey, VendNum, VendorName, PartNum, [Description], RetailPrice, JobberPrice, CorePrice, FederalExciseTax, PriceCode, OnHand, AltInventory, SpecialOrder, Reference
FROM
#FullResults
WHERE
(Row >= @Start) AND (Row <= @End)

GO


Michael Sumerano
Technical Web Administrator
eKeystone.com
http://www.ekeystone.com/

nr
SQLTeam MVY

12543 Posts

Posted - 2002-01-29 : 12:41:30
Put a
set nocount on
at the top of the sp.
Or look at the next recordset in VB.

It is probably returning a recordset for the rowcount from the temp table. An oledb feature.

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.

Edited by - nr on 01/29/2002 12:42:36
Go to Top of Page

sumo
Starting Member

45 Posts

Posted - 2002-01-29 : 12:55:38
I added the SET NOCOUNT ON to the top of the sp. Now, it returns an empty recordset. No more errors, but no records either.

quote:

Put a
set nocount on
at the top of the sp.
Or look at the next recordset in VB.

It is probably returning a recordset for the rowcount from the temp table. An oledb feature.



Michael Sumerano
Technical Web Administrator
eKeystone.com
http://www.ekeystone.com/

Edited by - sumo on 01/29/2002 12:58:10

Edited by - sumo on 01/29/2002 13:02:11
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-01-29 : 13:17:17
This will be because it isn't getting any rows from the query.
Try hard coding the statr and end rows in the query.
Try logging the parameters to a table at the top of the SP - you'll probably find they're not what you expect.


==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sumo
Starting Member

45 Posts

Posted - 2002-01-29 : 13:17:40
Doing a nextrecordset doesn't work either. :(

quote:

Put a
set nocount on
at the top of the sp.
Or look at the next recordset in VB.

It is probably returning a recordset for the rowcount from the temp table. An oledb feature.
y - nr on 01/29/2002 12:42:36



Michael Sumerano
Technical Web Administrator
eKeystone.com
http://www.ekeystone.com/
Go to Top of Page

sumo
Starting Member

45 Posts

Posted - 2002-01-29 : 13:32:25
Ok. I'm getting rows back now for some reason. However, the pagecount doesn't get returned properly. In query analyzer, it gets returned, but it is not appearing either back in the VB component or the asp page. The output parameter is the last parameter, I do an intPageCount = objParam.value. intPageCount is a variant passed to the component byref.

quote:

This will be because it isn't getting any rows from the query.
Try hard coding the statr and end rows in the query.
Try logging the parameters to a table at the top of the SP - you'll probably find they're not what you expect.



Michael Sumerano
Technical Web Administrator
eKeystone.com
http://www.ekeystone.com/
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-01-29 : 13:37:05
You will need to get all the rows back to the client before the output parameter is available (and possibly close the recordset).

I always work with client side disconnected recordsets so the parameters are available.

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sumo
Starting Member

45 Posts

Posted - 2002-01-29 : 13:39:10
The server-side cursor was the problem. Woohoo! It works!

THANK YOU SO MUCH!!!

quote:

You will need to get all the rows back to the client before the output parameter is available (and possibly close the recordset).

I always work with client side disconnected recordsets so the parameters are available.



Michael Sumerano
Technical Web Administrator
eKeystone.com
http://www.ekeystone.com/
Go to Top of Page
   

- Advertisement -