Skip to content

Commit 21a1962

Browse files
committed
raise TinyTds::Error and translate it. 'active?' method is rescuing just those
1 parent 6861763 commit 21a1962

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def finish_statement_handle(handle)
464464
end
465465

466466
def ensure_established_connection!
467-
raise ActiveRecord::ConnectionNotEstablished, 'SQL Server client is not connected' if @connection.nil? || !@connection.active?
467+
raise TinyTds::Error, 'SQL Server client is not connected' if @connection.nil? || !@connection.active?
468468

469469
yield
470470
end

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ def initialize_type_map(m = type_map)
374374
end
375375

376376
def translate_exception(e, message:, sql:, binds:)
377-
return e if e.is_a?(ActiveRecord::ConnectionNotEstablished)
378-
379377
case message
378+
when /SQL Server client is not connected/
379+
ConnectionNotEstablished.new(message)
380380
when /(cannot insert duplicate key .* with unique index) | (violation of unique key constraint)/i
381381
RecordNotUnique.new(message, sql: sql, binds: binds)
382382
when /(conflicted with the foreign key constraint) | (The DELETE statement conflicted with the REFERENCE constraint)/i

0 commit comments

Comments
 (0)