Forums | Admin

Discussion Forums: open-discussion

Start New Thread Start New Thread

 

By: Tim Haynes
RE: DSN-less connections [ reply ]  
2008-04-24 13:02
Hi,

You'll be pleased to know support for DSN-less connections is included in the 1.5 and 2.0 releases!

Regards,

~Tim

By: Ralf Vitasek
DSN-less connections [ reply ]  
2007-04-24 11:29
i needed to get the odbc adapter to work with connection strings too (not just system dsn's)
so i hacked in the logic from odbc.rb to the connection adapter. i haven't yet fully tested it but this is what i now have:

def self.odbc_connection(config) #:nodoc:
config = config.symbolize_keys
if config.has_key?(:dsn)
dsn = config[:dsn]
else
raise ActiveRecordError, "No data source name (DSN) specified."
end
username = config[:username] ? config[:username].to_s : nil
password = config[:password] ? config[:password].to_s : nil
trace = config[:trace].nil? ? false : config[:trace]
conv_num_lits = config[:convert_numeric_literals].nil? ? false : config[:convert_numeric_literals]
emulate_bools = config[:emulate_booleans].nil? ? false : config[:emulate_booleans]

driver_attrs = dsn.split(';')
if driver_attrs.length.eql?(1) # try system dsn
conn = ODBC::connect(dsn, username, password)
else # try connection string
driver = ::ODBC::Driver.new
driver.name = 'DSN-less'
driver_attrs.each do |param|
attr = param.split('=')
driver.attrs[attr[0]] = attr[1] if attr.length.eql?(2)
end
conn = ::ODBC::Database.new.drvconnect(driver)
end
conn.autocommit = true

ConnectionAdapters::ODBCAdapter.new(conn, {:dsn => dsn, :username => username,
:password => password, :trace => trace, :conv_num_lits => conv_num_lits,
:emulate_booleans => emulate_bools}, logger)
end

would be great if this functonality could be included in the next release