If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Retrieving temp table data from MS SQL using ASP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-19-03, 12:53
rodrich rodrich is offline
Registered User
 
Join Date: Jun 2003
Location: Panama City, FL
Posts: 2
Retrieving temp table data from MS SQL using ASP

I am trying to retrieve data from a stored procedure in MS SQL 2000 that has had to use temporary tables in coming up with the required dataset. However, when I call the procedure from a web page in which I am using VB script to call and retrieve the data, the recordset is always closed when I try to use it.

ex.

'Establish a connection with data source.
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.Open(application("DBconnNewBudgetRO"))

'Instantiate a Recordset object.
Set rs = Server.CreateObject("ADODB.Recordset")
strSQL = "aTest1 '" & Session("DataYear") & "'"
rs.Open strSQL, cnn

' ANY statement that trys to use the dataset rs gets the following error
' Operation is not allowed when object is closed
DO UNTIL rs.EOF <--- crash here
Response.Write rs.Fields("FundDocument") & vbCrLf
rs.MoveNext
LOOP

rs.Close
Set rs = nothing


There MUST be a way to return data from MS SQL that used temp tables to gather and format the records... but I have had no luck at all. HELP!?!?!?
Reply With Quote
  #2 (permalink)  
Old 06-24-03, 09:46
rhs98 rhs98 is offline
Super Moderator
 
Join Date: Feb 2002
Location: Hampshire, UK
Posts: 441
Whats the exact error
Reply With Quote
  #3 (permalink)  
Old 06-25-03, 21:09
rodrich rodrich is offline
Registered User
 
Join Date: Jun 2003
Location: Panama City, FL
Posts: 2
exact error

like I said in the example code... it complains that the recordset is closed when I try to do anything with it after a call to any stored procedure that used temp tables. The exact error message says 'Operation is not allowed when object is closed'. I am perplexed.
Reply With Quote
  #4 (permalink)  
Old 06-26-03, 14:21
Memnoch1207 Memnoch1207 is offline
Registered User
 
Join Date: Jan 2003
Location: Midwest
Posts: 138
This checks to see if the rs.state is closed (0), and if it is then it opens it.
Code:
If(rs.State = 0) then
   rs.State = 1
End if
Reply With Quote
  #5 (permalink)  
Old 07-02-03, 12:52
rhs98 rhs98 is offline
Super Moderator
 
Join Date: Feb 2002
Location: Hampshire, UK
Posts: 441
try this (no idea if it will work);
Code:
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.Open(application("DBconnNewBudgetRO"))

Set rs = Server.CreateObject("ADODB.Recordset")
strSQL = "aTest1 '" & Session("DataYear") & "'"
rs.Open strSQL, cnn

while not(rs.EOF)
 Response.Write rs.Fields("FundDocument") & vbCrLf
 rs.MoveNext
wend

rs.Close
Set rs = nothing
Reply With Quote
  #6 (permalink)  
Old 07-09-03, 18:57
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
Can you attach the code for the stored procedure?

You have to make sure you're doing a SELECT out of that temp table at the end of your stored procedure if you want it returned to your record set.

It should look similar to this:

Code:
CREATE PROCEDURE dbo.spMyStoredProc
    --Define your inbound parameters
AS
    SET NOCOUNT ON

    --Declared a bunch of variables

    CREATE TABLE #tempTable (col1 numeric, col2 varchar(50))

    --Do some work to find rows, and insert them into the temp table

    SELECT * FROM #tempTable
    DROP TABLE #tempTable

    SET NOCOUNT OFF
GO
Reply With Quote
  #7 (permalink)  
Old 09-29-03, 12:06
d96bfe d96bfe is offline
Registered User
 
Join Date: Sep 2003
Location: Belfast
Posts: 1
Re: Retrieving temp table data from MS SQL using ASP

I had been experiencing the same problem myself. I used the Set NoCount On and Set No Count Off but this still did not work for me. But when using this and also putting the code into a transaction this worked. I hope it also solves your problem.

My code now looks something like the following:

CREATE PROCEDURE sp_StoredProcName
@Param1 As varchar(10),
@Param2 As int
AS
BEGIN TRAN

SET NOCOUNT ON

CREATE TABLE #tempTable(Field1 varchar(10), Field2 int)

INSERT INTO #tempTable(Field1 varchar(10), Field2 int) Values(@Param1, @Param2)

SELECT * FROM #tempTable
DROP TABLE #tempTable

SET NOCOUNT OFF
COMMIT TRAN
GO
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On