1

I'm getting below error while retrieving records from account table in Dynamics CRM. Error message is in the screenshot below.

enter image description here

Could you please guide me what I'm doing wrong here.

Strange thing is that it is working in a console app. Hence I'm assuming the credentials are correct. But this is not working in SSIS Script Task. I'm a Data Engineer and doesn't have much experience in C#. One more story: This was previously working on other server and that server is decommissioned now. We've got a new server. The moment I executed he code on new server it gave me an error that the assembly was missing. I added the Microsoft.Xrm.Tooling.Connector.dll in GAC and now it is giving this error.

Shahab Haidar
  • 625
  • 3
  • 11
  • 25
  • 1
    Most likely, the response from your `.Execute()` call is `NULL`, so you cannot just dereference the `.UserId` from it.... read back the response, check for `response != null`, and only if that's true, **then** use `response.UserId` to get the user id.... basic defensive programming 101 .... – marc_s Sep 15 '22 at 19:47
  • check if with clientid&clientsecret authentication your code works – Guido Preite Sep 15 '22 at 22:25
  • 1
    Most likely the **organizationService** is not ready. You can use **organizationService.IsReady** to check the connection status and use **organizationService.LastCrmError** or **organizationService.LastCrmException** to get error info. – ray gan Sep 16 '22 at 01:54
  • Post the code and exception as *text* in the question itself. The error tells you that you tried to call a property or method on a `null` value. Are you *sure* that `Execute` returned anything? – Panagiotis Kanavos Sep 16 '22 at 10:08
  • @marc_s Strange thing is that it is working in a console app. Hence I'm assuming the credentials are correct. But this is not working in SSIS Script Task. I'm a Data Engineer and doesn't have much experience in C#. One more story: This was previously working on other server and that server is decommissioned now. We've got a new server. The moment I executed he code on new server it gave me an error that the assembly was missing. I added the Microsoft.Xrm.Tooling.Connector.dll in GAC and now it is giving this error. – Shahab Haidar Sep 16 '22 at 13:20
  • I would try it out in Postman before jumping into the actual code, so that you can ensure your credentials are correct. – Luis Gouveia Nov 12 '22 at 10:43

1 Answers1

1

Probably the passed credentials are not valid.

Use the CrmServiceClient.IsReady property to find out if a working connection has been established. If not, property LastCrmError should give you a clue about what went wrong. Property LastCrmException may also be useful.

var client = new CrmServiceClient(connectionString);

if (!client.IsReady)
{
    Console.WriteLine("Failed on first attempt. " + client.LastCrmError);

    // Try again, but now with login prompt. (LoginPrompt=Always)
    ...
Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42