Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3045

Show
Ignore:
Timestamp:
11/15/05 15:58:36 (3 years ago)
Author:
bitsweat
Message:

SQLServer: active? and reconnect! methods for handling stale connections. References #428.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r3044 r3045  
    11*SVN* 
    22 
    3 * SQLServer: active? and reconnect! methods for handling stale connections.  #428 [kajism@yahoo.com
     3* SQLServer: active? and reconnect! methods for handling stale connections.  #428 [kajism@yahoo.com, Tom Ward <tom@popdog.net>
    44 
    55* Associations handle case-equality more consistently: item.parts.is_a?(Array) and item.parts === Array.  #1345 [MarkusQ@reality.com] 
  • trunk/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb

    r3044 r3045  
    208208      # Returns true if the connection is active. 
    209209      def active? 
    210         @connection.execute("SELECT 1") {|sth|
     210        @connection.execute("SELECT 1") {
    211211        true 
     212      rescue DBI::DatabaseError, DBI::InterfaceError 
     213        false 
     214      end 
     215 
     216      # Reconnects to the database, returns false if no connection could be made. 
     217      def reconnect! 
     218        @connection.disconnect rescue nil 
     219        @connection = DBI.connect(*@connection_options) 
    212220      rescue DBI::DatabaseError => e 
     221        @logger.warn "#{adapter_name} reconnection failed: #{e.message}" if @logger 
    213222        false 
    214223      end 
    215  
    216       # Reconnects to the database. 
    217       def reconnect! 
    218         begin 
    219           @connection.disconnect 
    220           @connection = DBI.connect(*@connection_options) 
    221         rescue DBI::DatabaseError => e 
    222           @logger.warn "#{adapter_name} automatic reconnection failed: #{e.message}" 
    223         end 
    224       end 
    225  
    226  
    227224 
    228225      def select_all(sql, name = nil)