Notifications
Announcements
No record found.
Hello Experts,I am trying to create a console application in .NET which communicates with CRM so would perform CRUD operation but I am not able to connect getting error always. I am sharing the code snippet.using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Tooling.Connector; using System; namespace ConsoleAppWithD365 { class Program { static void Main(string[] args) { CrmServiceClient crmSvc = getOrganizationService(); Console.ReadLine(); } public static CrmServiceClient getOrganizationService() { CrmServiceClient crmSvc = null; String connectionString = "AuthType=OAuth;Username=xxxx@xxxx.onmicrosoft.com; Password=xxxx;Url=https://xxx.crm.dynamics.com;AppId=xxxx; RedirectUri=http://localhost;LoginPrompt=Auto"; try {; crmSvc = new CrmServiceClient(connectionString); if (crmSvc != null) { var whoAmIResponse = ((WhoAmIResponse)crmSvc.Execute(new WhoAmIRequest())); if (whoAmIResponse != null) { Console.WriteLine("Connection OK...."); Console.WriteLine(whoAmIResponse.UserId); } else { Console.WriteLine("Not Connected...."); } } } catch (Exception e) { Console.WriteLine("ERROR..."); Console.WriteLine(e.Message); } return crmSvc; } } }I have added Dynamics 365 SDK references to the project via NuGet.While using above code getting below error.I have registered the Application to the azure, Generated the Client secret also created the application user with the current application id by following steps given here : https://blog.magnetismsolutions.com/blog/paulnieuwelaar/2021/9/21/setting-up-an-application-user-in-dynamics-365Still getting error.
using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Tooling.Connector; using System; namespace ConsoleAppWithD365 { class Program { static void Main(string[] args) { CrmServiceClient crmSvc = getOrganizationService(); Console.ReadLine(); } public static CrmServiceClient getOrganizationService() { CrmServiceClient crmSvc = null; String connectionString = "AuthType=OAuth;Username=xxxx@xxxx.onmicrosoft.com; Password=xxxx;Url=https://xxx.crm.dynamics.com;AppId=xxxx; RedirectUri=http://localhost;LoginPrompt=Auto"; try {; crmSvc = new CrmServiceClient(connectionString); if (crmSvc != null) { var whoAmIResponse = ((WhoAmIResponse)crmSvc.Execute(new WhoAmIRequest())); if (whoAmIResponse != null) { Console.WriteLine("Connection OK...."); Console.WriteLine(whoAmIResponse.UserId); } else { Console.WriteLine("Not Connected...."); } } } catch (Exception e) { Console.WriteLine("ERROR..."); Console.WriteLine(e.Message); } return crmSvc; } } }
I can not use the Auth type Office 365 as it is depreciated. Please help to generate the OrgService to perform the CRUD operation in dynamics 365 using console app.
with an application user the connection string is authtype ClientSecret like this one
AuthType='ClientSecret'; Url='https://abc123.crm.dynamics.com/'; ClientId='xxx'; ClientSecret='yyy';
Guido Preite Still not able to establish connection with this connection string AuthType='ClientSecret'; Url='https://abc123.crm.dynamics.com/'; ClientId='xxx'; ClientSecret='yyy'; and getting same error.
Hi,
Can you try to connect with the clientid and clientsecret with XrmToolBox.
Once done, you can get the connection string via a button.
Hi Xavier Monin
I got connection string via XRMToolBox and used in below source code.
Still error is reproducible.
Your screenshots do not share the real error.
Can you please share the LastCrmError property of CrmServiceClient? See learn.microsoft.com/.../microsoft.xrm.tooling.connector.crmserviceclient.lastcrmerror
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Tom_Gioielli 74 Super User 2025 Season 2
Daniyal Khaleel 32 Most Valuable Professional
Gerardo RenterÃa Ga... 31 Most Valuable Professional