locked
Cannot connect to CRM 2016 SP1 via CRM 2016 SDK in C# code without hardcoding user credentials RRS feed

  • Question

  • We are testing upgrade from on-premise CRM 2013 to CRM 2016 SP1 [CRM 2013 -> CRM 2015-> CRM 2016 SP1].

    Our on-premise CRM version is 8.1.0.359 [2016 SP1].

    We have custom JavaScript activated on our custom Case form that calls a custom web service using AJAX. The custom web service (written in C#) tries to connect to the CRM via the CRM 2016 SDK to get and update attributes on the Case entity.

    The custom web service works in CRM 2013 with this basic connection string: “Url=http://crm/Organization”

    The custom web service has been updated to use the new CRM Tooling in CRM 2016 SDK. It does not work in the test CRM 2016 SP1 environment with the same basic connection string. The only way we can get it to work is to hardcode user credentials in the connection string like this: “Url=http://crm/Organization; Domain=ddd; Username=uuu; Password=ppp;

    What would cause user credentials to have to be hardcoded the connection string used by CRM 2016 SDK to connect to the CRM?

    With NO user credentials hardcoded, the SDK reports “Unable to Login to Dynamics CRM” as the last CRM exception.

    The C# code using the SDK looks like this:

    string connString = ConfigurationManager.ConnectionStrings["CrmConnectionString"].ConnectionString;

    Trace.WriteLine("Connecting to '" + connString + "'...");

    CrmServiceClient conn = new CrmServiceClient(connString);

    if (conn.IsReady)

    {

        Trace.WriteLine("Connected.");

    }

    else

    {

        Trace.WriteLine("CrmServiceClient.IsReady = " + conn.IsReady);

        Trace.WriteLine("CrmServiceClient.LastCrmError = " + conn.LastCrmError);

        Trace.WriteLine("CrmServiceClient.LastCrmException = " + conn.LastCrmException);

    }

    The tracing produced when user credentials are NOT hardcoded in the connection string is this:

    Connecting to 'Url=http://crm/Organization'...

    CrmServiceClient.IsReady = False

    CrmServiceClient.LastCrmError = Unable to Login to Dynamics CRM

    We tried various combinations of connection strings like these:

    "Url=http://crm/Organization;"

    "AuthenticationType=AD;Url=http://crm/Organization;"

    "Url=http://crm/Organization;AuthType=AD;"

    Using information from the "Developer Resources" page in the CRM UI, we tried this connection string too:

    "Url=http://crm/Organization/api/data/v8.1/;"

    Is there any additional configuration that must be done on the CRM or SQL servers to facilitate the SDK connecting to the CRM without having to hardcode credentials in the connection string?

    Thanks
    Thursday, February 2, 2017 2:34 PM

All replies

  • Hi.

    I am having the same problem.

    Did you find the solution?

    Thanks.

    Friday, October 20, 2017 10:27 PM
  • try this :-

     OrganizationServiceProxy serviceProxy = null;
    public string OrganizationUri =// "https://XXX.crmX.dynamics.com/XRMServices/2011/Organization.svc";
    public ClientCredentials Credentials = null;

       Credentials = new ClientCredentials();
                Credentials.UserName.UserName = "";
              
                Credentials.UserName.Password = ""

     serviceProxy = new OrganizationServiceProxy(new Uri(OrganizationUri), null, Credentials, null);

     Console.ReadLine();


    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Monday, October 23, 2017 6:39 AM