Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Unable to Login to Dynamics CRM online via a Console application

Posted on by 1,004

Hi,

I am trying to connect to Dynamics CRM Online via a console application. I manged to connect successfully when I use the service account. But if I use any other user I get the following error as the last CRM error in conn object; so the orgService is null: (these users can login to CRM and do their work.)

Unable to Login to Dynamics CRMOrganizationWebProxyClient is nullOrganizationServiceProxy is nullOrganizationServiceProxy is nullOrganizationServiceProxy is nullOrganizationWebProxyClient is nullOrganizationServiceProxy is nullOrganizationWebProxyClient is nullOrganizationServiceProxy is null

Here is my code:

private static string connectionString = "Url=orgname.crm6.dynamics.com; Username=username@example.com; Password=password; authtype=Office365";

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            
CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);


IOrganizationService orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

I have tried using the organization unique name instead of org name in the connection string as suggested here:

http://missdynamicscrm.blogspot.in/2017/02/error-unable-to-login-to-dynamics.html

and also this one:

https://www.solzit.com/resolve-error-unable-login-dynamics-crmorganizationwebproxyclient-null-crm-online/

Nothing works.

*This post is locked for comments

  • Suggested answer
    Vipin J Profile Picture
    Vipin J 1,583 on at
    RE: Unable to Login to Dynamics CRM online via a Console application

    Here is a quick solution

    https://vjcity.blogspot.com/2021/10/unable-to-login-to-dynamics.html

    https://vjcity.blogspot.com/2021/07/assembly-microsoftcrmsdkproxy-with.html

    Here is a complete Step by Step approach to connect to D365 CRM

    https://vjcity.blogspot.com/2021/12/connect-to-dynamic-365-crm-from-console.html

  • Suggested answer
    Nishant Rana Profile Picture
    Nishant Rana 55 Microsoft Employee on at
    RE: Unable to Login to Dynamics CRM online via a Console application

    We were also getting the same error - this helped

    nishantrana.me/.../

  • Verified answer
    Justinjose Profile Picture
    Justinjose 2,707 on at
    RE: Unable to Login to Dynamics CRM online via a Console application

    Hi SCV,

    I am not sure tried this or not.

    Known Issue with Visual Studio 2015

    When you are running your project/solution in VS 2015 in debug mode, there is a known issue where you may not be able to connect to Dynamics 365 (online), version 9.0. This happens regardless of whether you are using a Target Framework of 4.6.2 or higher. This can occur because the Visual Studio hosting process is compiled against .NET 4.5 which means by default it does not support TLS 1.2. You can disable the Visual Studio hosting process as a work around. Right-click on the name of your project in Visual Studio and then click Properties. On the Debug tab you can uncheck the Enable the Visual Studio hosting process option.

    Please Note: This only impacts the debug experience in VS 2015. This does not impact the binaries or executable that are built. The same issue does not occur in Visual Studio 2017.

    Thanks

    Justin Jose

  • Verified answer
    Friyank Profile Picture
    Friyank 944 on at
    RE: Unable to Login to Dynamics CRM online via a Console application

    This is because,

    CRM 365 9.0 connection  is only possible using TLS 1.2

    Hope this blog here helps you

    coderscollection.wordpress.com/.../607

  • Verified answer
    M.T. Eikelenboom Profile Picture
    M.T. Eikelenboom 5,241 on at
    RE: Unable to Login to Dynamics CRM online via a Console application

    Maybe it is due to CRM forcing you to use TLS 1.2? I had the same error using an Azure Function and forcing TLS 1.2 solved it for me.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Unable to Login to Dynamics CRM online via a Console application

    Can you try and check if the following works?

    using Microsoft.Xrm.Tooling.Connector;

    string userName = ConfigurationManager.AppSettings["UserName"].ToString();

    string password = "password"

    string internalUrl = ConfigurationManager.AppSettings["InternalUrl"].ToString();

    string orgName = ConfigurationManager.AppSettings["OrgName"].ToString();

    NetworkCredential creds = new NetworkCredential(userName, ConvertToSecureString(password));

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    // Next two lines use Microsoft.Xrm.Tooling.Connector namespace;

    AuthenticationType authType = AuthenticationType.Office365;

    conn = new CrmServiceClient(userName, ConvertToSecureString(CRM_PASSWORD), "NorthAmerica", orgName, isOffice365: true);

    if (conn.IsReady)

    {

      _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

    }

    Not sure if this will resolve your issue, but I had issues in the past with connection string as well.

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans