rails-sqlserver / activerecord-sqlserver-adapter

SQL Server Adapter For Rails
MIT License
975 stars 563 forks source link

configure_connection not getting called #213

Closed fpauser closed 12 years ago

fpauser commented 12 years ago

My setting: Linux, TinyTDS-0.91, Ruby-1.9.3, Rails-3.2.6

I added the following initializer to configure my connection to the db (config/initializers/sqlserver.rb):

Rails.logger.info "Connection settings..."

module ActiveRecord
  module ConnectionAdapters
    class SQLServerAdapter < AbstractAdapter
      def configure_connection
        Rails.logger.info "Setting custom connection settings..."
        raw_connection_do "SET ARITHABORT ON"
        raw_connection_do "SET CONCAT_NULL_YIELDS_NULL ON"
      end
    end
  end
end

But configure_connection is never getting called - my log just prints "Connection settings...".

Checking the current connection settings in rails console via ActiveRecord::Base.connection.exec_query "DBCC USEROPTIONS" also confirms that there were no custom connection settings set:

irb(main):002:0> ap ActiveRecord::Base.connection.exec_query "DBCC USEROPTIONS"
  SQL (1.9ms)  EXEC sp_executesql N'DBCC USEROPTIONS'
#<ActiveRecord::Result:0x050396e8
    @hash_rows = nil,
    attr_reader :columns = [
        [0] "Set Option",
        [1] "Value"
    ],
    attr_reader :rows = [
        [ 0] [
            [0] "textsize",
            [1] "2147483647"
        ],
        [ 1] [
            [0] "language",
            [1] "us_english"
        ],
        [ 2] [
            [0] "dateformat",
            [1] "mdy"
        ],
        [ 3] [
            [0] "datefirst",
            [1] "7"
        ],
        [ 4] [
            [0] "lock_timeout",
            [1] "-1"
        ],
        [ 5] [
            [0] "quoted_identifier",
            [1] "SET"
        ],
        [ 6] [
            [0] "ansi_null_dflt_on",
            [1] "SET"
        ],
        [ 7] [
            [0] "ansi_warnings",
            [1] "SET"
        ],
        [ 8] [
            [0] "ansi_padding",
            [1] "SET"
        ],
        [ 9] [
            [0] "ansi_nulls",
            [1] "SET"
        ],
        [10] [
            [0] "isolation level",
            [1] "read committed"
        ]
    ]
>

Tried with latest master and version 3.2.5.

metaskills commented 12 years ago

Hmmm, there is not a lot that can go wrong here. Perhaps your Gemfile is not requiring the adapter gem or you have some other setup where it is lazily loaded? If so, try putting a `require 'activerecord-sqlserver-adapter`` at the top of that initializer file.

metaskills commented 12 years ago

BTW, I have a #user_options method in the adapter you can use. https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/active_record/connection_adapters/sqlserver/database_statements.rb#L132

metaskills commented 12 years ago

Closing this unless needed, I know of quite a few other people that are using this hook. So I have to assume that you are doing something a bit different in your gem requires or something, hence my suggestion for the top level require. Please let me know if this is still not working for you and/or what you have found out. I will re-open if needed.