I am having problems with a paging system within my ASP applicationI am working off an article from [url]http://www.15seconds.com/issue/010308.htm[/url] entitled "Paging: Use ADO, getrows, or a Stored Procedure?".I have adapted the SP and it works really well in Query Analyser, but when I call it from my ASP application, it errors (ADODB.Recordset (0x800A0E78) Operation is not allowed when the object is closed.)Here's my ASP codestrSQL = "EXECUTE dfGetForumSummaryPage @fid=" & oForumID & ", @days=" & fSortDays & ", @page=" & oPageID & _ ", @pageSize=" & fPageTopic & ", @sortkey='" & fSortKey & "', @sortorder='" & fSortOrder & "'"Set rsForum = dbConn.Execute( strSQL )If NOT rsForum.EOF Then <-- Errors here
If I take that completed statement above and drop it in Query Analyser, it works just fine.Here's the stored procedure:CREATE PROCEDURE dfGetForumSummaryPage @fid INT, @days INT, @page INT, @pageSize INT, @sortkey VARCHAR(25), @sortorder VARCHAR(25)ASDECLARE @sql AS VARCHAR(200)DECLARE @start INTDECLARE @end INTDECLARE @pageBoundary INT-- Get our start and end position for our rowsSET @start = ((@page-1) * @pageSize) + 1IF @@ERROR<> 0 RETURN @@ERRORSET @end = @start + @pageSize - 1-- Create our temporary holding table for the recordsetBEGIN TRANSACTION GetDataSetCREATE TABLE #PostTemp ( RowID int IDENTITY(1,1) PRIMARY KEY, PostID int)IF @@ERROR<>0 GOTO ErrorHandler-- Insert the required PostIDs for this querySELECT @sql = 'INSERT INTO #PostTemp (PostID) SELECT PostID FROM dbForumPosts 'SELECT @sql = @sql + 'WHERE (ForumID=' + CONVERT(VARCHAR(4),@fid) + ') AND (Parent=0) AND (deleted=0) AND 'SELECT @sql = @sql + '(LastPostDate > DATEADD(d,' + CONVERT(VARCHAR(4),-@days) + ',GETDATE()))'SELECT @sql = @sql + ' ORDER BY ' + @sortkey + ' ' + @sortorderEXEC( @sql )IF @@ERROR<>0 GOTO ErrorHandler-- Get our upper bound for the pageSELECT @pageBoundary=MAX(RowID) FROM #PostTemp-- Check our lower bounds for this pageIF @start > @pageBoundary GOTO ErrorHandler-- Check our upper bounds for this pageIF @end > @pageBoundary SET @end = @pageBoundary-- Now SELECT the records requiredSELECT #PostTemp.PostID, dbo.dbForumPosts.Subject, dbo.dbForumPosts.AuthorID, dbo.dbUserInfo.Handle, dbo.dbForumPosts.NumViews, dbo.dbForumPosts.NumReplies, dbo.dbForumPosts.LastPostDate, dbo.dbForumPosts.ForumIDFROM #PostTemp INNER JOIN dbo.dbForumPosts ON #PostTemp.PostID = dbo.dbForumPosts.PostID INNER JOIN dbo.dbUserInfo ON dbo.dbForumPosts.AuthorID = dbo.dbUserInfo.UserIDWHERE ((#PostTemp.RowID >=@start) AND (#PostTemp.RowID <=@end))DROP TABLE #PostTemp <--Is this necessary?COMMIT TRANSACTION GetDataSetRETURN 0ErrorHandler:ROLLBACK TRANSACTION GetDataSetRETURN @@ERRORGO
Should I get rid of the temporary table and use a normal one? Does the temporary table die when the SP returns?I am a real newbie to SQL Server, but am loving the learning experience that I am having as it is a whole new and more exciting world than Access, that's for sure 