Friday, October 14, 2005

SSPI connection for Rails SQLServer connection adapter

Recently, I added support for SSPI (a connection that uses your local user account to authenticate you on the database server without supplying another password). To use an SSPI connection, do not supply a username or a password.

sqlserver_adapter.rb:

username = config[:username] ? config[:username].to_s : ''
...
# Use integrated security
if config[:integrated] or (username == '' and password == '')
conn = DBI.connect("DBI:ADO:Provider=SQLOLEDB;Data Source=#{host};Initial Catalog=#{database};Integrated Security=SSPI;")
else
conn = DBI.connect("DBI:ADO:Provider=SQLOLEDB;Data Source=#{host};Initial Catalog=#{database};User Id=#{username};Password=#{password};")
end

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home