Skip to main content

Notifications

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

Failure in Conexion CRM On Line

Posted on by 688

Good afternoon,

I'm creating a class that connects to CRM On Line version v.9.2, but I'm getting the error "Unable to Login to Dynamics CRMOrganizationServiceProxy is null", can someone help me, below is the code I'm using

D365ConsoleCRUD namespace
{
class Program
{
static void Main(string[] args)
{
OAuthConnexion connection = new OAuthConnexion();
CrmServiceClient svc = connection.ConnectionOAuth();

if(svc.IsReady)
{
Console.WriteLine("With Connection");
}
else
{
Console.WriteLine("No Connection");
}

}
}
}

public class OAuthConnection
{
public CrmServiceClient ConnectionOAuth()
{

string url = "">xxxxxx.crm2.dynamics.com";
string userName = "xxxx@hotmail.com";
string passWord = "xxxxx";

string con = $@"
Url = {url};
AuthType = Office365;
userName = {userName};
passWord = {passWord};
RequiredNewInstance = True";

CrmServiceClient svc = new CrmServiceClient(con);
return svc;
}


}

  • RE: Failure in Conexion CRM On Line

    Hello Arshad,

    Thanks for the feedback, I tried your way and failed, I tried from the article optimallogics.com/.../ , but success.

    Create the connection string and nothing, I believe that it is missing some parameter.

    Here's the code I'm using

    Void main:

    using (CrmServiceClient svcClient = new CrmServiceClient(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))

                   {

                       if (!svcClient.IsReady)

                       {

                           Console.WriteLine("unable to connect!");

                           return;

                       }

                       WhoAmIRequest request = new WhoAmIRequest();

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

                       Console.WriteLine("UserId =" + response.UserId.ToString());

                   }

    APP Config:

    <connectionStrings>

       <add name="ConnectionStrings"

            connectionString="

             AuthType=ClientSecret;url=XXXXX.crm2.dynamics.com;

             ClientID=XXXXXX-126c-XXXX-a87b-XXXXXX;

             ClientSecret='XXXX-XXXX-XXXX-aceb-XXXXXX"/>

     </connectionStrings>

    The error I'm getting is

    Object reference not set to an instance of an object

    Thanks

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Failure in Conexion CRM On Line

    Hi,

    • using System;
    • using Microsoft.Azure.WebJobs;
    • using Microsoft.Azure.WebJobs.Host;
    • using Microsoft.Extensions.Logging;
    • using Microsoft.PowerPlatform.Dataverse.Client;
    • using Microsoft.Xrm.Sdk;
    • namespace Timer_Trigger
    • {
    •     public static class Function1
    •     {
    •         [FunctionName("Function1")]
    •         public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
    •         {
    •             log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    •             Connect();
    •             Entity e = new Entity();
    •         }
    •         public static void Connect()
    •         {
    •             //  log.LogInformation("C# HTTP trigger function processed a request.");
    •             ServiceClient crmServiceClient = null;
    •             System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
    •             var clientId = "8182544c-3485-4bc3-9884-81617d48e39a";
    •             var clientSecret = "8jm7Q~nhPHGP0Ccl-6a5ow2Tivf4LzADLdZMR";
    •             var organizationUrl = "">org13ffb2c4.crm8.dynamics.com/";
    •             string connectionString = "Url=" + organizationUrl + "; " +
    •             "AuthType=ClientSecret; " +
    •             "ClientId= " + clientId + "; " +
    •             "ClientSecret=" + clientSecret;
    •             crmServiceClient = new ServiceClient(connectionString);
    •             if (crmServiceClient.IsReady)
    •             {
    •                 CreateRecord(crmServiceClient);
    •             }
    •         }
    •         private static void CreateRecord(ServiceClient crmServiceClient)
    •         {
    •             try
    •             {
    •                 Entity newAccount = new Entity("account");
    •                 newAccount["name"] = "Account is crated through Azure";
    •                 crmServiceClient.Create(newAccount);
    •                 //Write the program here
    •             }
    •             catch (Exception)
    •             {
    •                 throw;
    •             }
    •         }
    •     }
    • }

    https://juniorazurecrm.blogspot.com/   you can also find code and explanation here.

    www.youtube.com/watch  This video tell you how to create record in crm once the authentication done.

    please like and subscribe my YouTube channel and blog for interview question.

    https://www.youtube.com/watch?v=X7H25FZHoF0&t=3s

    https://juniorcrmblog.blogspot.com/

    Thanks,

    Arshad

    Thanks

  • RE: Failure in Conexion CRM On Line

    Hi Shaun,

    How is everything? Thanks for replying, do you have an example using this command?

  • Shaun W Harvey Profile Picture
    Shaun W Harvey 240 on at
    RE: Failure in Conexion CRM On Line

    Hi Ricardo,

    You are still using an Office365 AuthType which has now been deprecated.

    You now need to use an AuthType = OAuth and a modified connection string.

    See the deprecation note from Microsoft below.

    Use of Office365 authentication with Microsoft Dataverse (Microsoft Dataverse) - Power Apps | Microsoft Docs

    Hopefully modifying the connection string should allow you to connect.

    Regards,

    Shaun

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans