Results 1 to 8 of 8

Thread: [RESOLVED] Problem with ADODB Command & Stored procedure

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    32

    Resolved [RESOLVED] Problem with ADODB Command & Stored procedure

    I have a problem registering parameters for a stored procedure.

    Please see this SP carefully.
    Code:
    CREATE PROCEDURE [dbo].[proc1] @ObjectType numeric AS
     SET NOCOUNT ON
     DECLARE @ObjectID INT
     BEGIN TRANSACTION
       UPDATE tblObject
       SET
           m_lCurrentObjectID = m_lCurrentObjectId + 1,
           @ObjectID = m_lCurrentObjectId + 1
         WHERE
           m_lObjectId = @ObjectType
     COMMIT TRANSACTION
     RETURN @ObjectID
    That's it, we take an input parameter of type : NUMERIC, update a value in table
    Return the updated value as a return value from SP, type INTEGER.

    Now the ADODB portion of the code :
    Code:
    Set command = New ADODB.command
        command.ActiveConnection = myConn
        command.CommandType = adCmdStoredProc
        command.CommandText = "dbo.proc1"
        
        Set param1 = command.CreateParameter("ObjectType", adNumeric, adParamInput, 10)
        
        command.Parameters.Append param1
        param1.Value = 105
        Set param2 = command.CreateParameter("ObjectID", adInteger, adParamReturnValue, 10)
        command.Parameters.Append param2
        command.Execute
    I get an exception : "Mutiple step OLE DB operation generated errors.

    I dont understand why !
    Can someone help me pls...

    Thanks.
    Last edited by Hack; Feb 24th, 2009 at 11:40 AM. Reason: Added Code Tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Problem with ADODB Command & Stored procedure

    Moved To Database Development

  3. #3
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Problem with ADODB Command & Stored procedure

    Is this SQL Server ?

    Should your SP Input Variable be of type - Int ?

    Also can we see your Connection Code, where MyConn is being opened ?
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    32

    Re: Problem with ADODB Command & Stored procedure

    Quote Originally Posted by NeedSomeAnswers
    Is this SQL Server ?

    Should your SP Input Variable be of type - Int ?

    Also can we see your Connection Code, where MyConn is being opened ?
    Hi, Thanks for your time.

    Yes, it is SQL Server, SP can't be changed.
    MyConn is all good, because I just tried calling another SP which does not take any parameters, the same code worked fine. I could call & execute that SP.

    ^^ I mean to say, if i repalce the SP name & cut off the parameters portion in the "same" VB code posted above, i could execute an SP.

    Problem here is with the parameters & the way i am handling it i guess. Do you see any issue in the VB code i posted here ?

    Thanks again for your time.
    Last edited by vnatar; Feb 24th, 2009 at 12:10 PM.

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Problem with ADODB Command & Stored procedure

    Try removing the values for the sizes.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    32

    Re: Problem with ADODB Command & Stored procedure

    Quote Originally Posted by dee-u
    Try removing the values for the sizes.
    No luck ! Same error : "Mutiple step OLE DB operation generated errors.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Problem with ADODB Command & Stored procedure

    you need to reverse how you add the parameters... RETURN values ALWAYS come first.... and they don't need a parameter name....
    Code:
    Set command = New ADODB.command
        command.ActiveConnection = myConn
        command.CommandType = adCmdStoredProc
        command.CommandText = "dbo.proc1"
        
        Set param2 = command.CreateParameter("RETURNVALUE", adInteger, adParamReturnValue, 10)
        command.Parameters.Append param2
    
        Set param1 = command.CreateParameter("ObjectType", adNumeric, adParamInput, 10)
        
        command.Parameters.Append param1
        param1.Value = 105
        command.Execute
    
    messagebox.show command.parameters("RETURNVALUE").Value.tostring
    See if that works.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    32

    Resolved Re: Problem with ADODB Command & Stored procedure

    Quote Originally Posted by techgnome
    you need to reverse how you add the parameters... RETURN values ALWAYS come first.... and they don't need a parameter name....
    Code:
    Set command = New ADODB.command
        command.ActiveConnection = myConn
        command.CommandType = adCmdStoredProc
        command.CommandText = "dbo.proc1"
        
        Set param2 = command.CreateParameter("RETURNVALUE", adInteger, adParamReturnValue, 10)
        command.Parameters.Append param2
    
        Set param1 = command.CreateParameter("ObjectType", adNumeric, adParamInput, 10)
        
        command.Parameters.Append param1
        param1.Value = 105
        command.Execute
    
    messagebox.show command.parameters("RETURNVALUE").Value.tostring
    See if that works.

    -tg
    That was easy
    Thanks a lot bro, it worked.

    I'm a newbie, i never knew that there is an order !

    Thanks[a ton] again.

Posting Permissions

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



Click Here to Expand Forum to Full Width