Skip to content

Commit e9f9885

Browse files
author
Aidan Haran
committed
Fix reconnection
1 parent a6c80d4 commit e9f9885

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,8 @@ def config_encoding(config)
118118

119119
def initialize(connection, logger, _connection_options, config)
120120
super(connection, logger, config)
121-
122121
@connection_options = config
123-
@spid = _raw_select("SELECT @@SPID", fetch: :rows).first.first
124-
@version_year = version_year
125-
126-
initialize_dateformatter
127-
use_database
122+
configure_connection
128123
end
129124

130125
# === Abstract Adapter ========================================== #
@@ -285,6 +280,14 @@ def reset!
285280
do_execute "IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION"
286281
end
287282

283+
def configure_connection
284+
@spid = _raw_select("SELECT @@SPID", fetch: :rows).first.first
285+
@version_year = version_year
286+
287+
initialize_dateformatter
288+
use_database
289+
end
290+
288291
# === Abstract Adapter (Misc Support) =========================== #
289292

290293
def tables_with_referential_integrity
@@ -501,6 +504,13 @@ def version_year
501504
def sqlserver_version
502505
@sqlserver_version ||= _raw_select("SELECT @@version", fetch: :rows).first.first.to_s
503506
end
507+
508+
private
509+
510+
def connect
511+
@connection = self.class.new_client(@connection_options)
512+
configure_connection
513+
end
504514
end
505515
end
506516
end

0 commit comments

Comments
 (0)