Skip to content

ServiceClient is not connected to Dataverse. Please recreate this ServiceClient #499

Description

Hi,

We are having some random issues with the ServiceClient connections when using it from our service bus queue triggered Azure Functions. These are hosted on an App Service Plan Premium v3 P1V3, with Always On enabled, no auto scaling and one 1 instance.
We are getting the error "ServiceClient is not connected to Dataverse. Please recreate this ServiceClient". Looking at the code, I see that happens when the ValidateConnectionLive method is called prior to any call to Dataverse. So my guess is that the connection works fine for a while, but then at some point the IsReady is set to false and because the _connectionOptions is null we get that error.

internal void ValidateConnectionLive()
{
if (isDisposed)
{
// This client has been disposed and no property of it can be trusted. Thrown Exception should bubble to caller.
throw new ObjectDisposedException("This instance of the ServiceClient has been disposed and cannot be used. You must create a new ServiceClient instance.");
}

        if (!this.IsReady)
        {
            if (this._connectionOptions != null)
            {
                var failureExecpt = new DataverseConnectionException("ServiceClient is Staged for Connection but not Connected. You must call .Connect() on this client before using it.");
                _logEntry?.Log(failureExecpt);
                throw failureExecpt;
            }
            else
            {
                var failureExecpt = new DataverseConnectionException("ServiceClient is not connected to Dataverse. Please recreate this ServiceClient.");
                _logEntry?.Log(failureExecpt);
                throw failureExecpt;
            }
        }
    }

At the beginning of our function code, we call the constructor ServiceClient(X509Certificate2 certificate, StoreName certificateStoreName, string certificateThumbPrint, Uri instanceUrl, bool useUniqueInstance, OrganizationDetail orgDetail, string clientId, Uri redirectUri, ILogger logger = null) and we used the same instance through the entire execution. The useUniqueInstance parameter is set to false, so it means we are reusing the cached connection if any.

My question is, what can cause the connection to go down? Should we implement a retry mechanism to catch DataverseConnectionException exceptions and authenticate again? Or is there something we can change on the code to avoid those issues?

Please let me know if you need further information to assess the issue.

Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions