Skip to content

Commit

Permalink
Avoid exception when db-connection is lost
Browse files Browse the repository at this point in the history
The tiny_tds lib might return false on execute when the call fails.
This caused exceptions when active? is called after the connection
was lost.

fixes rails-sqlserver#707
  • Loading branch information
Sven Felix Oberquelle committed Dec 17, 2019
1 parent ed8b170 commit 77e1d01
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ def sp_executesql_sql(sql, types, params, name)
def raw_connection_do(sql)
case @connection_options[:mode]
when :dblib
@connection.execute(sql).do
result = @connection.execute(sql)
result == false ? false : result.do
end
ensure
@update_sql = false
Expand Down
3 changes: 1 addition & 2 deletions lib/active_record/connection_adapters/sqlserver_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ def disable_referential_integrity

def active?
return false unless @connection
raw_connection_do 'SELECT 1'
true
raw_connection_do('SELECT 1') == 1
rescue *connection_errors
false
end
Expand Down

0 comments on commit 77e1d01

Please sign in to comment.