DBI stateHandler bind_param errors

D

David Lee

I have a real problem with calling a stored procedure on MS SQL Server
from Ruby-DBI. I have no problems with connections or calling queries.
I can even call the Stored procedure with "exec Test 'test'" and the
stored procedure inserts the value text into a Test table. However, if
I try to use the bind_param to add the input params to a stored
procedure to make my class alitte more friendly it ERRORs.

OUTPUT ____
Connection Successful !!!
Preparing SQL Query: exec Test
Executing SQL Stmt
Error INTERN (0) [RubyODBC]Too much parameters
____________________

CODE ____________

begin
connection_string = "DBI:ODBC:Driver={SQL
Server};Server=#{@adapter_config["acct_db_host"]};Database=#{@adapter_config["acct_db_name"]};Uid=#{@adapter_config["acct_db_user"]};Pwd=#{@adapter_config["acct_db_pass"]}"
connect( connection_string, @adapter_config["acct_db_user"],
@adapter_config["acct_db_pass"] )
is_connected
prepare( "exec Test" )
bind_param( 1, "Admin1" )
execute
#puts "Return_Code: " + get_return_code
#puts "Return_Status: " + get_return_status
rescue DBI::DatabaseError => e
puts "Error #{e.errstr}"
rollback
ensure
#disconnect from server
disconnect
end
end

def connect( connection_string, db_user, db_pass )
@db = DBI.connect( connection_string )
end

def disconnect
@db.disconnect if @db
end

def is_connected
if @db.ping
puts "Connection Successful !!!"
else
puts "Connection FAILED !!!"
end
#@db.ping
end

def execute
puts "Executing SQL Stmt"
@stmt.execute
end

def prepare( query )
puts "Preparing SQL Query: " + query
@stmt = @db.prepare( query )
end

# attribs is not yet used in this version, but could later be a hash
containing more
# information like parameter type, etc.
def bind_param( param, value )
@stmt.bind_param( param, value, false )
end
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top