Changed handling of dead connections #2
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Suggested changes related to rails-sqlserver#903:
Do not check if a connection is dead/alive before using it. Using
connection.active?
would mean an extra call to the database for every query. We will know whether the connection is dead based on whether TinyTds::Error("failed to execute statement") is thrown. Removed!@connection.active?
from https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/903/files#diff-f749b206a3bbfaa7e02aa77f1c26715bea21134aa6d2645cbf9068783e280cf8R467If a connection is disconnected or dead then a
ConnectionNotEstablished
should be thrown. The disconnection part is already done. We just need to check if the connection was dead. This can be detected by checking for the "failed to execute statement" error message when translating the exception (https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/903/files#diff-3562da8bff63a7b06dce2a8b9e1163ab5598cca3bcaaf1b971a1c3e40942b053R378).