Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Trying to Retrieve CRM Data via an SSIS Script Component using CRM Connection Manager

Posted on by Microsoft Employee

I have a transformation script component within a data flow task - using KingswaySoft. 

However, I get the error "Object reference not set to an instance of an object" when the script task executes.

I pass an SSIS variable into the component called "ContactGUID". The component also has 1 input, "CRMRecordId", which is the GUID of the custom entity I want to retrieve the x_contact value from. The component has a CRMConnection manager and one output column added.

My first question is there anyway to debug Script Components? I have tried setting a message box/break points - but the object error appears as soon as the script component is reached within the data flow.

Here is my code:

#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using KingswaySoft.IntegrationToolkit.DynamicsCrm;
using KingswaySoft.DynamicsCrmServices.Soap2011;
using KingswaySoft.DynamicsCrmServices.Soap2011.OrganizationService.Query;
using KingswaySoft.DynamicsCrmServices.Soap2011.OrganizationService;
using KingswaySoft.DynamicsCrmServices.Soap2011.OrganizationService.Messages;
using KingswaySoft.DynamicsCrmServices.Soap2011.OrganizationService.Metadata;
         
using System.ServiceModel.Description;
using Microsoft.SqlServer.Dts.Pipeline;
using System.Runtime.Serialization;
#endregion

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
  
    public IOrganizationService _service;
    KingswaySoft.DynamicsCrmServices.Soap2011.OrganizationService.IOrganizationService orgService;
    public override void PreExecute()
    {
        Console.WriteLine("starting pre-execute");
        base.PreExecute();
   
        var connMgr = this.Connections.CrmConnection;
        var connectionString = (string)connMgr.AcquireConnection(null);
        var conn = new CrmConnection(connectionString);
        var orgService = (IOrganizationService)conn.GetCrmService(); // SOAP 2011
    }

    public override void PostExecute()
    {
        base.PostExecute();
    }

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        ColumnSet cols = new ColumnSet(
                        new String[] { "x_contact" });

        Entity contactIdentifier = orgService.Retrieve("x_contactidentifier", Row.CrmRecordId, cols);

        if (contactIdentifier.Contains("x_contact"))
       {
              Variables.ContactGUID = Convert.ToString(contactIdentifier.Attributes["x_contact"]);
       }

    }
}


When I comment out the call to "orgService" the error is no longer - which leads me to believe it may be something todo with the "Pre-Execute" Method.

Any help would be much appreciated - Thanks

Additional Information:

CRM 365 Online

SQL Server 2017

*This post is locked for comments

  • Daniel Cai Profile Picture
    Daniel Cai 935 on at
    RE: Trying to Retrieve CRM Data via an SSIS Script Component using CRM Connection Manager

    Hi Praveen, sorry for the late response, I think I missed the notification for this discussion thread. Yes, the code will work for CDS connection as well. If you run in Azure SSIS-IR, it should work the same. Note that what's behind an Azure SSIS-IR is a virtual machine (or container) which behaves like a typical system, and you have full control of the system during the time of provisioning including GAC'ing or copying any files if needed.

  • RE: Trying to Retrieve CRM Data via an SSIS Script Component using CRM Connection Manager

    Hi Daniel,

    Will the above code work for D365 CDS connection also? I wounder If I have to deploy my SSIS package in Azure as a pipeline and will it be able to get the required dll's?

    I have similar requirement in my project.

    Thank you in advance!

  • Suggested answer
    Michel Gueli Profile Picture
    Michel Gueli 982 on at
    RE: Trying to Retrieve CRM Data via an SSIS Script Component using CRM Connection Manager

    replace:

    var orgService = (IOrganizationService)conn.GetCrmService(); // SOAP 2011

    With:

    _service = (IOrganizationService)conn.GetCrmService(); // SOAP 2011

    And Replace:

    Entity contactIdentifier = orgService.Retrieve("x_contactidentifier", Row.CrmRecordId, cols);

    with:

    Entity contactIdentifier = _service.Retrieve("x_contactidentifier", Row.CrmRecordId, cols);

    The solution of Daniel Cai will also work.

  • Verified answer
    Daniel Cai Profile Picture
    Daniel Cai 935 on at
    RE: Trying to Retrieve CRM Data via an SSIS Script Component using CRM Connection Manager

    The following line of code is essentially hiding the class variable. 

    var orgService = (IOrganizationService)conn.GetCrmService(); // SOAP 2011

    You need to make sure that you are not declaring a new local variable, so it should be something like the following. 

    orgService = (IOrganizationService)conn.GetCrmService(); // SOAP 2011

    Hope this is helpful. 

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Trying to Retrieve CRM Data via an SSIS Script Component using CRM Connection Manager

    Error when script component executes:

    5618.ssis.PNG

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans