seanmcne / Microsoft.Xrm.Data.PowerShell

This module uses the CRM connection from Microsoft.Xrm.Tooling.CrmConnector.Powershell and provides common functions to create, delete, query, and update data as well as functions for common tasks such as publishing, and manipulating System & CRM User Settings, etc. The module should function for both Dynamics CRM Online and On-Premise environment.
201 stars 64 forks source link

Connect-CrmOnline - intermittent connection failure #520

Open ryan950ng opened 1 year ago

ryan950ng commented 1 year ago

Hi,

I am using the Connect-CrmOnline to connect to the server in my Gitlab pipeline, but the connection will fail intermittently. Sometimes it works after a few retry.

    Import-Module Microsoft.Xrm.Data.PowerShell
    Set-CrmConnectionTimeout -TimeoutInSeconds 600
    $conn.OrganizationWebProxyClient.Endpoint.Binding.SendTimeout.TotalMinutes

    Connect-CrmOnline -ConnectionTimeoutInSeconds 600 -ClientSecret $oAuthClientSecret -OAuthClientId $oAuthClientId -ServerUrl $CRMDestinationUrl

This is the error returned:

WARNING: Please reconnect to the service after setting the connection timeout or the new timeout will *not* be used for
 operations.
IsReady                             : False
IsBatchOperationsAvailable          : False
MaxRetryCount                       : 10
RetryPauseTime                      : 00:00:05
Authority                           : 
ActiveAuthenticationType            : ClientSecret
OAuthUserId                         : 
TenantId                            : 00000000-0000-0000-0000-000000000000
EnvironmentId                       : 
ConnectedOrgId                      : 00000000-0000-0000-0000-000000000000
CrmConnectOrgUriActual              : https://[Masked]/XRMServices/2011/Organization.svc
ConnectedOrgFriendlyName            : 
ConnectedOrgUniqueName              : 
ConnectedOrgVersion                 : 
SdkVersionProperty                  : 9.2.47.9489
CallerId                            : 00000000-0000-0000-0000-000000000000
CallerAADObjectId                   : 
DisableCrossThreadSafeties          : False
SessionTrackingId                   : 
ForceServerMetadataCacheConsistency : False
LastCrmError                        : One or more errors occurred. => An error occurred while sending the request. => 
                                      Unable to connect to the remote server => A connection attempt failed because 
                                      the connected party did not properly respond after a period of time, or 
                                      established connection failed because connected host has failed to respond 
                                      40.119.215.132:443ERROR REQUESTING Token FROM THE Authentication context - 
                                      General ADAL Error
                                      One or more errors occurred. => An error occurred while sending the request. => 
                                      Unable to connect to the remote server => A connection attempt failed because 
                                      the connected party did not properly respond after a period of time, or 
                                      established connection failed because connected host has failed to respond 
                                      40.119.215.132:443One or more errors occurred. => An error occurred while 
                                      sending the request. => Unable to connect to the remote server => A connection 
                                      attempt failed because the connected party did not properly respond after a 
                                      period of time, or established connection failed because connected host has 
                                      failed to respond 40.119.215.132:443Unable to connect to CRM: An error occurred 
                                      while sending the request.
                                      One or more errors occurred. => An error occurred while sending the request. => 
                                      Unable to connect to the remote server => A connection attempt failed because 
                                      the connected party did not properly respond after a period of time, or 
                                      established connection failed because connected host has failed to respond 
                                      40.119.215.132:443Unable to Login to Dynamics CRM
                                      Unable to Login to Dynamics CRMOrganizationWebProxyClient is null
                                      OrganizationWebProxyClient is null
An error has occurred: One or more errors occurred. => An error occurred while sending the request. => Unable to connect to the remote server => A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 40.119.215.132:443ERROR REQUESTING Token FROM THE Authentication context - General ADAL Error
One or more errors occurred. => An error occurred while sending the request. => Unable to connect to the remote server => A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 40.119.215.132:443One or more errors occurred. => An error occurred while sending the request. => Unable to connect to the remote server => A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 40.119.215.132:443Unable to connect to CRM: An error occurred while sending the request.
One or more errors occurred. => An error occurred while sending the request. => Unable to connect to the remote server => A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 40.119.215.132:443Unable to Login to Dynamics CRM
Unable to Login to Dynamics CRMOrganizationWebProxyClient is null
OrganizationWebProxyClient is null************ NullReferenceException - ExecuteAsync : AsyncImportRequest |=> Object reference not set to an instance of an object.
Object reference not set to an instance of an object.[TerminalFailure] Failed to Execute Command - ExecuteAsync : RequestID=[Masked] : AsyncImportRequest duration=00:00:00.0117927 ExceptionMessage = Object reference not set to an instance of an object.
Object reference not set to an instance of an object.

The confusing part is due to the intermittent failure, and I have tried timeout and it's still having the same error.

seanmcne commented 1 year ago

It looks to be an error stating the request to acquire an auth token failed due to a timeout - you could use a try/catch to retry the connection on a failure to acquire an auth token.

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 40.119.215.132:443 ERROR REQUESTING Token FROM THE Authentication context - General ADAL Error One or more errors occurred.

ryan950ng commented 1 year ago

Few things that I have tried:

None of the method is working