Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection Timeout Does not work for values less than 15 seconds; Workaround available #35

Open
ADMDTO-Jack opened this issue Jun 19, 2024 · 0 comments

Comments

@ADMDTO-Jack
Copy link

ADMDTO-Jack commented Jun 19, 2024

Known issue with .net core older versions:

when connecting like so (ignore my own variables, relevant entry is ConnectionTimeout 1:
invoke-sqlcmd2 -ServerInstance $serverinstance -Database $database -Query $queryStr -SqlParameters $sqlparams -ConnectionTimeout 1 -ErrorAction Stop

the timeout actually still takes the full 15 seconds

this is related to issue:
dotnet sqlclient issue
workaround comment

I found it works utilizing the comment's suggestion, by adding the following lines to Invoke-SqlCmd2.ps1 at line 456 (inside of process foreach sqlinstance in serverinstance):

if ($ConnectionTimeout -lt 15 -and $ConnectionTimeout -gt 0) {
    Write-Debug "Setting MultiSubnetFailover to enforce sub-15s connection timeout"
    $CSBuilder["MultiSubnetFailover"] = $true
}

Reproduction: Attempt to invoke-sqlcmd2 with various connection timeout values set, to a sql server which does not exist on the network.

Workaround not necessarily recommended but posted here for reference, as it does appear to have the intended result. Higher timeouts and 0 timeouts not affected by this .net bug

(Note that setting timeout to 1s is not recommended, as it significantly increases failure rate without any particular connection/network issues. But with this change it would be possible.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant