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 :
Microsoft Dynamics CRM (Archived)

SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

(0) ShareShare
ReportReport
Posted on by

Greetings:

I'm trying the examples in the SDK, and now I'm at the Simplified Connecting String Example listed here [https://msdn.microsoft.com/en-us/library/jj602970(v=crm.7).aspx]

This is my code in the app.config:

 

<add name="Server=CRM Online, organization=contoso, user=someone"
         connectionString="Url=https://pspas.crm.dynamics.com;
Username=nxxxx.mxxxz@pspas.onmicrosoft.com;
Password=xxxx;
authtype=Office365"/>


However, I'm receiving the following error:

I'm using VS 2015 and I'm trying to connect to CRM Online 2016.

What I'm missing in my connection string?

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Ups the error image is not showing...

      

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2: Unable to Login to Dynamics CRM
    
    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2: OrganizationWebProxyClient is null
    
    
    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2: OrganizationServiceProxy is null
    
    
    The application terminated with an error.
    
    
    Object reference not set to an instance of an object.
    


  • ansrikanth Profile Picture
    3,115 on at

    what is the error you are getting ? and at what line/place?

  • Community Member Profile Picture
    on at

    Don't know why the images are not being posted Srikanth. But no I've updated my post above to include the error. Thank you.

  • Suggested answer
    ansrikanth Profile Picture
    3,115 on at

    Well, it's clearly showing that there is authentication failure and so the Org service is null. But you are trying to access properties/methods of it, you will get object reference errors.

    Step1 - Make sure your connection string (user id, password, url) is correct. An example of connection string from MSDN 

    <add name="MyCRMServer" connectionString="AuthType=Office365;Username=jsmith@contoso.onmicrosoft.com; Password=passcode;Url=contoso.crm.dynamics.com"/>

    Step2- If you are following the MSDN Example as it is, check what is the "connectionString" variable value you are getting in the "Run" method
    is it what we are expecting or getting any other?

    You can also check Organizationservice's last error/fault property to check for more details on why authentication failed (AFAIK).
  • Community Member Profile Picture
    on at

    Checked step1 and step2. I'm receiving the same error. Credentials, username, password, and url are correct.

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    Please try the steps provided in the blog below to establish the connection to CRM. It provides a simple example too.

    arunpotti.wordpress.com/.../connect-to-crm-online-or-on-premise-using-c

    Hope this helps.

  • Suggested answer
    Nadeeja Bomiriya Profile Picture
    6,804 on at

    Hi NellMartinez,

    I just tested this and had issues with the latest version of Microsoft.IdentityModel.Clients.ActiveDirectory assembly.  I downgraded it to 2.28.0 and it works.

    Here's the code.

    var connectionString = "Url=https://orgname.crm.dynamics.com; Username=user@orgname.onmicrosoft.com; Password=password; authtype=Office365";
    
    // Connect to the CRM web service using a connection string.
    CrmServiceClient conn = new CrmServiceClient(connectionString);
    
    // Cast the proxy client to the IOrganizationService interface.
    var _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
    

    Please see below for the NuGet packages and versions I have installed in my console app.

    NuGet-Packages.PNG

  • Community Member Profile Picture
    on at

    Hi Nithya;

    My connection strings looks like this at this moment:  

    <add name="Server=CRM Online"         connectionString="Url=disco.crm.dynamics.com/.../v8.1;Username=xxxx.xxxx@pspas.onmicrosoft.com;Password=xxxx!;Domain:pspas;"/>

    And now I'm receiving this error;

    The application terminated with an error.

    Organization name cannot be null or empty.

    Parameter name: Organization Name

    {System.ArgumentNullException: Organization cannot be null or empty.

    Parameter name: Organization Name

      at Microsoft.Xrm.Tooling.Connector.CrmServiceClient.ConnectToCrmWebService(String crmConnectionString)

      at Microsoft.Xrm.Tooling.Connector.CrmServiceClient..ctor(String crmConnectionString)

      at Microsoft.Crm.Sdk.Samples.SimplifiedConnection.Run(String connectionString, Boolean promptforDelete) in C:\Development\CRM\SDK\SampleCode\CS\QuickStart\SimplifiedConnection.cs:line 70

      at Microsoft.Crm.Sdk.Samples.SimplifiedConnection.Main(String[] args) in C:\Development\CRM\SDK\SampleCode\CS\QuickStart\SimplifiedConnection.cs:line 285}

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    You could use the following connection string.

    Url=https://devcrm.vzdev.ch/devcrm;Domain=vzdev;UserName=user@vzdev.ch;Password=pass;AuthType=IFD

    Also refer the link below.

    https://msdn.microsoft.com/en-in/library/mt608573.aspx

    See: https://community.dynamics.com/crm/f/117/t/199661

           https://community.dynamics.com/crm/f/117/t/197001

    Hope this helps.

  • Suggested answer
    ansrikanth Profile Picture
    3,115 on at

    you shouldn't be using the Discovery service to connect to CRM Organization. Have you tried the solution provided by @Nadeeja Bomiriya above?

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans