# Ruby-odbc and OUTPUT params not working

**URL:** <https://www.ruby-forum.com/t/ruby-odbc-and-output-params-not-working/163476>\
**Category:** Ruby\
**Created:** [March 20, 2009, 6:53pm UTC](https://www.ruby-forum.com/t/ruby-odbc-and-output-params-not-working/163476 "2009-03-20T18:53:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 20, 2009, 6:53pm UTC](https://www.ruby-forum.com/t/ruby-odbc-and-output-params-not-working/163476/1 "2009-03-20T18:53:41Z")

</div>

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
