web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Connecting to MFA enabled Dynamics 365 CRM instance through console application

(0) ShareShare
ReportReport
Posted on by 505

Hello Experts,

I'm trying to connect to dynamics 365 CRM instance through console application but getting 'Unable to login to CRM' error.

Here is my code.

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
string connectionString = "AuthType=ClientSecret; url=myorg.crm.dynamics.com; ClientId=b77e2b5a-3946-485e-########; ClientSecret=s.tOrEuew_QTuGxV8Y0v4iTK######;

CrmServiceClient crmServiceClient = new CrmServiceClient(connectionString);
if (crmServiceClient != null && crmServiceClient.IsReady)
{
Console.WriteLine("\nConnection successful.");
}

I performed all the steps mentioned in this link:

https://nemely.com/blog/connect-to-multi-factor-enabled-d365-cds-programmatically-online-9-1/

Thanks,

Priyank

I have the same question (0)
  • Suggested answer
    Rui Carvalho Profile Picture
    on at

    Hello Priyank

    You are using WS Trust authentication and that's deprecated.

    docs.microsoft.com/.../authenticate-office365-deprecation

    Try to go with this sample instead:

    docs.microsoft.com/.../sample-simplified-connection-quick-start

    Or you can download the whole sample here:

    github.com/.../QuickStartCS

  • Suggested answer
    MMK Profile Picture
    745 on at

    Hi

    for any body who is struggling to connect old Console Application code with MFA Enabled CRM

    To Connect MFA Enabled Dynamics CRM with C# you just need to use App Password instead of your Password remaining every thing remains same as it was

                   string connectionString = GetServiceConfigurationfromAppCOnfig();

                  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                  CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);                

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

                  WhoAmIResponse whoAmIResponse = (WhoAmIResponse)_orgService.Execute(new WhoAmIRequest());

    Follow the Steps to generate App password

    community.dynamics.com/.../connecting-to-mfa-enabled-dynamics-365-v9-x-crm-instance-through-c-or-console-app

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans