Skip to content

Commit

Permalink
fixing connection timeout in 2.8.10 (#435)
Browse files Browse the repository at this point in the history
* fixing connection timeout
  • Loading branch information
seanmcne authored Sep 3, 2020
1 parent 5ee79a8 commit 0d57198
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
RootModule = 'Microsoft.Xrm.Data.Powershell.psm1'

# Version number of this module.
ModuleVersion = '2.8.10'
ModuleVersion = '2.8.11'

# ID used to uniquely identify this module
GUID = '7df9c140-65c3-4862-b3bc-73fad633aae4'
Expand Down
12 changes: 10 additions & 2 deletions Microsoft.Xrm.Data.PowerShell/Microsoft.Xrm.Data.PowerShell.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function Connect-CrmOnline{
if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent -eq $true) {
Enable-CrmConnectorVerboseLogging
}

if(-not [string]::IsNullOrEmpty($ServerUrl) -and $ServerUrl.StartsWith("https://","CurrentCultureIgnoreCase") -ne $true){
Write-Verbose "ServerUrl is missing https, fixing URL: https://$ServerUrl"
$ServerUrl = "https://" + $ServerUrl
Expand All @@ -136,7 +137,7 @@ function Connect-CrmOnline{
if($BypassTokenCache){
$cs += ";TokenCacheStorePath="
}

if($ForceDiscovery){
#SkipDiscovery is true by default and generally not necessary
Write-Verbose "ForceDiscovery: SkipDiscovery=False"
Expand All @@ -151,6 +152,13 @@ function Connect-CrmOnline{
}
}

if($ConnectionTimeoutInSeconds -and $ConnectionTimeoutInSeconds -gt 0){
$newTimeout = New-Object System.TimeSpan -ArgumentList 0,0,$ConnectionTimeoutInSeconds
Write-Verbose "Setting new connection timeout of $newTimeout"
#set the timeout on the MaxConnectionTimeout static
[Microsoft.Xrm.Tooling.Connector.CrmServiceClient]::MaxConnectionTimeout = $newTimeout
}

if($ConnectionString){
if(!$ConnectionString -or $ConnectionString.Length -eq 0){
throw "Cannot create the CrmServiceClient, the connection string is null"
Expand Down Expand Up @@ -189,7 +197,7 @@ function Connect-CrmOnline{
}
}
else{
if(-not [string]::IsNullOrEmpty($Username)){
if(-not [string]::IsNullOrEmpty($Username) -and $ForceOAuth -eq $false){
$cs += ";Username=$UserName"
Write-Warning "UserName parameter is only compatible with oAuth, forcing auth mode to oAuth"
$ForceOAuth = $true
Expand Down

0 comments on commit 0d57198

Please sign in to comment.