|
-
May 6th, 2001, 03:01 AM
#1
Thread Starter
New Member
Stored procedure
Dear experts,
I encounter this error below when I run the VB code and stored procedure.
Run-time error '3704'.
Operation is not allowed when the object is closed
The VB code and T-SQL procedure are stated below:
-- VB Code --------------------------------------------------------------------
Dim cd As New ADODB.Command
Dim rs As ADODB.Recordset
cd.CommandType = adCmdStoredProc
cd.CommandText = "GetCustomers"
Set rs = cd.Execute
While Not rs.EOF
dblCustomerNumber = rs!CUSTOMER_ID
strCustomerAddress = rs!CUSTOMER_ADDRESS
rs.MoveNext
Wend
-------------------------------------------------------------------------------
-- T-SQL Procedure ------------------------------------------------------------
CREATE PROCEDURE GetCustomers
AS
BEGIN
DECLARE @customer_id as datetime,
@customer_address as varchar(50)
CREATE TABLE #CUSTOMERS (
CUSTOMER_ID DECIMAL(13) NOT NULL,
CUSTOMER_ADDRESS VARCHAR(50) NULL
)
-- Declare local cursor to retrieve data from table CUSTOMERS
DECLARE cc CURSOR LOCAL FOR
SELECT CUSTOMER_ID, CUSTOMER_ADDRESS
FROM CUSTOMERS
FOR READ ONLY
OPEN cc
-- Loop and change all customer 5 addresses
WHILE 1 = 1 BEGIN
FETCH cc
INTO @customer_id, @customer_address
IF @@FETCH_STATUS <> 0 BREAK
IF @customer_id = 5 BEGIN
@customer_addresss = 'Newcastle'
END
INSERT INTO #CUSTOMERS (CUSTOMER_ID, CUSTOMER_ADDRESS)
VALUES @customer_id, @customer_address
END
SELECT * FROM #CUSTOMERS
CLOSE cc
DEALLOCATE cc
END
-------------------------------------------------------------------------------
I suspect that the object to retrieve the recordset from T-SQL stored procedure to VB code is closed. However I have already declare cursor cc as LOCAL. I suspect that the object is a global cursor and I have no idea why the it was closed. I suspect it has something to do with using cursor at the same time returning recordsets back to the VB code.
Could you please kindly advice me on how to solve this problem? Thank you very much in advance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|