Forum: Ruby ruby-odbc and OUTPUT params not working

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2009-03-20 18:53
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
# /*
# EXEC dbo.up_TestSP4 10, @P2 OUTPUT
# */

# 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'

  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")
  stmt.cancel if stmt
  conn.disconnect if conn && conn.connected?
This topic is locked and can not be replied to.