Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

CRM connection code stopped working suddenly

Posted on by 505

Hi Experts,

I was using the following code to connect to Dynamics CRM 2016 on-premise. It has stopped working suddenly.

ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = ConfigurationManager.AppSettings["Username"].ToString();
credentials.UserName.Password = ConfigurationManager.AppSettings["Password"].ToString();
string soapOrgServiceUri = ConfigurationManager.AppSettings["CRMOrgServiceUrl"].ToString();
Uri serviceUri = new Uri(soapOrgServiceUri);
OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
proxy.EnableProxyTypes();
service = (IOrganizationService)proxy;
_client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(proxy);
return service;

CrmServiceClient object's LastCrmError property shows 'Unable to Login to Dynamics CRMOrganizationServiceProxy is null'.

How can I fix this issue?

Thanks,

Priyank

  • Suggested answer
    CRMJetty Profile Picture
    CRMJetty 3,508 on at
    RE: CRM connection code stopped working suddenly

    Hello,

    Pls, refer this thread,

    https://nishantrana.me/2018/04/24/unable-to-login-to-dynamics-crmorganizationserviceproxy-is-null-error-while-using-crmserviceclient/

    https://nishantrana.me/2018/04/24/unable-to-login-to-dynamics-crmorganizationserviceproxy-is-null-error-while-using-crmserviceclient/


    I hope it helps,

    Thanks.

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365

  • Priyank Bhavsar Profile Picture
    Priyank Bhavsar 505 on at
    RE: CRM connection code stopped working suddenly

    Thanks for your suggestions everyone. It was a trust failure issue on ADFS server. After fixing it, the code is now working.

  • Suggested answer
    Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 on at
    RE: CRM connection code stopped working suddenly

    Hi,

    Please try the same below line at the top of your code:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

    After adding above line


    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    ClientCredentials credentials = new ClientCredentials();
    credentials.UserName.UserName = ConfigurationManager.AppSettings["Username"].ToString();
    credentials.UserName.Password = ConfigurationManager.AppSettings["Password"].ToString();
    string soapOrgServiceUri = ConfigurationManager.AppSettings["CRMOrgServiceUrl"].ToString();
    Uri serviceUri = new Uri(soapOrgServiceUri);
    OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
    proxy.EnableProxyTypes();
    service = (IOrganizationService)proxy;
    _client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(proxy);
    return service;

    Add reference of "Using system.net" in code.

    Also, you can refer below link
    https://www.briteglobal.com/blogs/community/choosing_crm_connection_option/

    Here, we need to define EndpointType. That is Microsoft.Xrm.Sdk.Client.AuthenticationProviderType.Federation; For IFD

    Thanks,
    Pradeep.

  • Priyank Bhavsar Profile Picture
    Priyank Bhavsar 505 on at
    RE: CRM connection code stopped working suddenly

    Hi Ramprakash,

    We are not using MFA.  Authentication type we are using is IFD without MFA.

  • Ram Prakash Profile Picture
    Ram Prakash 2,285 on at
    RE: CRM connection code stopped working suddenly

    Hi Priyank Bhavsar,

    Please try using Application User with MultiFactor Authentication

    https://microsoftcrmtechie.blogspot.com/2021/03/connect-to-multi-factor-enabled-d365.html

    Please mark as Answer if its helpful

  • RE: CRM connection code stopped working suddenly

    Hello, I recommend you to use a "connectionString",

    Check the verified answer of this thread: community.dynamics.com/.../unable-to-login-to-dynamics-crmorganizationserviceproxy-is-null

    Thanks!

    Community Support Team - Esteban

    If this post helps, consider Accept as a solution to help other members find it more quickly.

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans