aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb19
2 files changed, 9 insertions, 12 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 55ba45904e..2557eeb98f 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,6 +1,6 @@
*SVN*
-* SQLServer: active? and reconnect! methods for handling stale connections. #428 [kajism@yahoo.com]
+* SQLServer: active? and reconnect! methods for handling stale connections. #428 [kajism@yahoo.com, Tom Ward <tom@popdog.net>]
* Associations handle case-equality more consistently: item.parts.is_a?(Array) and item.parts === Array. #1345 [MarkusQ@reality.com]
diff --git a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
index 78486a2a1a..9320717b34 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
@@ -207,24 +207,21 @@ module ActiveRecord
# Returns true if the connection is active.
def active?
- @connection.execute("SELECT 1") {|sth|}
+ @connection.execute("SELECT 1") { }
true
- rescue DBI::DatabaseError => e
+ rescue DBI::DatabaseError, DBI::InterfaceError
false
end
- # Reconnects to the database.
+ # Reconnects to the database, returns false if no connection could be made.
def reconnect!
- begin
- @connection.disconnect
- @connection = DBI.connect(*@connection_options)
- rescue DBI::DatabaseError => e
- @logger.warn "#{adapter_name} automatic reconnection failed: #{e.message}"
- end
+ @connection.disconnect rescue nil
+ @connection = DBI.connect(*@connection_options)
+ rescue DBI::DatabaseError => e
+ @logger.warn "#{adapter_name} reconnection failed: #{e.message}" if @logger
+ false
end
-
-
def select_all(sql, name = nil)
select(sql, name)
end