ruby-odbc and OUTPUT params not working

Discussion in 'Ruby' started by Chris Hall, Mar 20, 2009.

  1. Chris Hall

    Chris Hall Guest

    connecting to an SQLExpress database to run a stored procedure, and
    output parameters are not working. If anyone has any help they can
    give, it would be greatly appreciated.

    require 'rubygems'
    require 'odbc'

    # CREATE PROCEDURE dbo.up_TestSP4(@NotUsed INT, @ReturnVar INT OUTPUT)
    # AS
    # SET @ReturnVar = 666
    # /*
    # DECLARE @P2 INT
    # EXEC dbo.up_TestSP4 10, @P2 OUTPUT
    # SELECT @P2
    # */

    # Error:
    # 2000 (8162) [FreeTDS][SQL Server]The formal parameter "@P2" was not
    # declared as an OUTPUT parameter, but the actual parameter passed in
    # requested output.
    # odbc_test.rb:26:in `execute'

    begin
    conn = ODBC::Database.connect("dsn", "xxx", "xxx")
    stmt = conn.prepare("exec dbo.up_TestSP4 ?, ?")
    stmt.param_iotype(1, ODBC::SQL_PARAM_OUTPUT)
    stmt.param_output_type(1, ODBC::SQL_INTEGER)
    stmt.param_output_size(1, 4)
    res = stmt.execute(1, nil)
    out_value = stmt.param_output_value(1)
    puts "#{out_value}"
    rescue Exception => e
    puts e
    puts e.backtrace.join("\n")
    ensure
    stmt.cancel if stmt
    conn.disconnect if conn && conn.connected?
    end
    --
    Posted via http://www.ruby-forum.com/.
    Chris Hall, Mar 20, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andy6
    Replies:
    2
    Views:
    756
    andy6 via DotNetMonster.com
    Jun 9, 2006
  2. Java script Dude
    Replies:
    2
    Views:
    291
    Java script Dude
    Jan 29, 2006
  3. Barry
    Replies:
    9
    Views:
    441
    Ara.T.Howard
    Sep 15, 2005
  4. Wes Gamble
    Replies:
    1
    Views:
    159
    Gerardo Santana Gómez Garrido
    Apr 5, 2006
  5. Replies:
    0
    Views:
    102
Loading...

Share This Page