1 class ActiveRecord::Base
3 def mssql_connection(config)
5 config[:host] ||= "localhost"
7 config[:driver] ||= "net.sourceforge.jtds.jdbc.Driver"
9 url = "jdbc:jtds:sqlserver://#{config[:host]}:#{config[:port]}/#{config[:database]}"
11 # Instance is often a preferrable alternative to port when dynamic ports are used.
12 # If instance is specified then port is essentially ignored.
13 url << ";instance=#{config[:instance]}" if config[:instance]
15 # This will enable windows domain-based authentication and will require the JTDS native libraries be available.
16 url << ";domain=#{config[:domain]}" if config[:domain]
18 # AppName is shown in sql server as additional information against the connection.
19 url << ";appname=#{config[:appname]}" if config[:appname]
23 config[:username] ||= "sa"
24 config[:password] ||= ""
26 jdbc_connection(config)
28 alias_method :jdbcmssql_connection, :mssql_connection