Results 1 to 3 of 3

Thread: Stored procedure

  1. #1
    New Member
    Join Date
    May 01
    Location
    Malaysia
    Posts
    1

    Unhappy 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.

  2. #2
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 00
    Location
    Buenos Aires, Argentina
    Posts
    6,810
    I didn't read that much the code... But aren't you forgetting to set the active connection to your command?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  3. #3
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 00
    Location
    Buenos Aires, Argentina
    Posts
    6,810

    DAMNIT!!

    I really don't know squat 'bout it. I would like to help you but have no clue what the problem could be. I don't know it the active connection was your problem or not. However, I use the idea of your T-SQL to make one of my own. I needed something like you did. Create a temporary table and change one field of all the records. I MADE IT It works great in the ISQL/w. However, I get the same error as you got. Just after the rs.open Statement, ADOConnection, the recordset appears to be closed.
    If you found out what was going on, I would be glad to know your solution. Thanks in advance,
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •