Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/active_record/connection_adapters/sqlserver_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ def type_map

def translate_exception(exception, message:, sql:, binds:)
case message
when /(SQL Server client is not connected)|(failed to execute statement)|(failed dbsqlsend)/i
when /(SQL Server client is not connected)|(failed to execute statement)|(failed dbsqlsend)/i,
/(DBPROCESS is dead or not enabled)/i
ConnectionNotEstablished.new(message, connection_pool: @pool)
when /(cannot insert duplicate key .* with unique index) | (violation of (unique|primary) key constraint)/i
RecordNotUnique.new(message, sql: sql, binds: binds, connection_pool: @pool)
Expand Down
8 changes: 8 additions & 0 deletions test/cases/adapter_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
assert_raise(ActiveRecord::StatementInvalid) { Topic.lease_connection.update("UPDATE XXX") }
end

it "translates a dead DBPROCESS TinyTds error into a connection not established error" do
exception = TinyTds::Error.new("DBPROCESS is dead or not enabled")
translated = connection.send(
:translate_exception, exception, message: exception.message, sql: "SELECT 1", binds: []
)
assert_kind_of ActiveRecord::ConnectionNotEstablished, translated
end

it "is has our adapter_name" do
assert_equal "SQLServer", connection.adapter_name
end
Expand Down
Loading