Skip to content

Commit 459c2be

Browse files
authored
Merge pull request #825 from rails-sqlserver/adjust-dead-connection-error-message
Adjust error message when connection is dead
2 parents 60e2f0c + 7dabfb1 commit 459c2be

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [#812](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/812) Rails 6: Coerce ReloadModelsTest test on Windows
1111
- [#818](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/818) Handle false return by TinyTDS if connection fails and fixed CI
1212
- [#819](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/819) Fix Ruby 2.7 kwargs warnings
13+
- [#825](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/825) Adjust error message when connection is dead
1314

1415
#### Changed
1516

lib/active_record/connection_adapters/sqlserver/database_statements.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,12 @@ def raw_connection_do(sql)
353353
case @connection_options[:mode]
354354
when :dblib
355355
result = @connection.execute(sql)
356-
# If connection fails then TinyTDS returns false instead of an exception (see https://github.com/rails-sqlserver/tiny_tds/issues/464)
357-
if result == false
358-
raise TinyTds::Error, 'TinyTDS execute returned false instead of results'
359-
end
356+
357+
# TinyTDS returns false instead of raising an exception if connection fails.
358+
# Getting around this by raising an exception ourselves while this PR
359+
# https://github.com/rails-sqlserver/tiny_tds/pull/469 is not released.
360+
raise TinyTds::Error, 'failed to execute statement' if result.is_a?(FalseClass)
361+
360362
result.do
361363
end
362364
ensure

0 commit comments

Comments
 (0)