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

can't connect to dataverse in c#

(1) ShareShare
ReportReport
Posted on by

i want to connect to my dynamic 365 dataverse and by my first environment its works fine but now its not working,this is the steps that i do, i go to azure active directory and register a app with Multitenant access, and make api permissions to dataverse/dynamics and create a client secret but i get an error by trying to connect to dataverse here is my code 

static void Main(string[] args)
{
string url = "">mydomain.crm.dynamics.com";
// e.g. you@yourorg.onmicrosoft.com

string conn = $@"
Url = {url};
AuthType = ClientSecret;

AppId = myappid;
ClientSecret =my client secret;
RedirectUri = login.microsoftonline.com/.../nativeclient;
LoginPrompt=Auto;
RequireNewInstance = True";

using (var svc = new CrmServiceClient(conn))
{

WhoAmIRequest request = new WhoAmIRequest();

WhoAmIResponse response = (WhoAmIResponse)svc.Execute(request);

Console.WriteLine("Your UserId is {0}", response.UserId);

Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}

and i get an error System.NullReferenceException: 'Object reference not set to an instance of an object.', by the line WhoAmIResponse response = (WhoAmIResponse)svc.Execute(request);

and by a other connection method i get a response 

The HTTP request was forbidden with client authentication scheme 'Negotiate'.

if anyone can guide me what step i missing in the app configuration 

thanks 

I have the same question (0)
  • Guido Preite Profile Picture
    54,086 Moderator on at

    your connection string is a bit strange, try with one more simple:

    AuthType='ClientSecret'; Url='mywonderfulorg.crm.dynamics.com'; ClientId='00000000-0000-0000-0000-000000000000'; ClientSecret='MyWonderfulClientSecret';

    change your values and try again

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Before you use svc check IsReady property of it. I believe it will be false. Also check what you have in LastCrmError/LastCrmException - it should give you an answer why your code doesn't work.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Guido Preite quotes in connection string? Are you sure it's legit?

  • Guido Preite Profile Picture
    54,086 Moderator on at

    yes, single quotes are allowed (mostly for the scenario when the password/clientsecret contains a semicolor or equals sign

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Oh, I use this stuff almost the last decade and had no need for it. New day, new lesson. Thanks, Guido Preite!

  • mof Profile Picture
    on at

    its works fine in the other enviorement

  • mof Profile Picture
    on at

    thanks for your reply , i get this in svc.LastCrmError

    Invalid Login Information : The HTTP request was forbidden with client authentication scheme 'Anonymous'.

    The HTTP request was forbidden with client authentication scheme 'Anonymous'. => The remote server returned an error: (403) Forbidden.Unable to Login to Dynamics CRM

    Unable to Login to Dynamics CRM

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Did you add App User to the instance you're trying to connect to?

  • mof Profile Picture
    on at

    thanks a much,yes i forgot from this important step

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    If my reply (or replies) answers your question take a minute and verify the answer. You can do it by clicking "Yes" at the top of the reply (or replies) under the label "Does this answer your question?"

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 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans