Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to use two CrmServiceClient to connect with two CRM instances?

(1) ShareShare
ReportReport
Posted on by 327

Hello Friends,

Currently I am trying to copy data from one crm instance to another using CrmServiceClient, ASP.NET C#. But when I create two objects of

CrmServiceClient, only first instance object (primary endpoint) will be taken into consideration as a connection for the application. It is not taking second CrmServiceClient object to insert data. Actually it is inserting data in the instance from which it was copying data.

Could you please let me know why I am not able to use second CrmServiceClient object to insert copied data or how to change primary endpoints ?

Many Thanks,

Pradip

*This post is locked for comments

  • Vishal Giri Profile Picture
    Vishal Giri 15 on at
    RE: How to use two CrmServiceClient to connect with two CRM instances?

    Worked well.

  • Verified answer
    Pradip Raj Profile Picture
    Pradip Raj 327 on at
    RE: How to use two CrmServiceClient to connect with two CRM instances?

    Hi Andrii,

    You are right. Thank you so much for all your help.

    Also we can set "useUniqueInstance: true" in CrmServiceClient constructor.

    CrmServiceClient crmSvc = new CrmServiceClient("SourceOrgUsername", CrmServiceClient.MakeSecureString("SourceOrgPassword"), "IND", "SFW", useUniqueInstance: true, useSsl: false, isOffice365: true);

    Many Thanks,

    Pradip

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: How to use two CrmServiceClient to connect with two CRM instances?

    So as I suggested before - add RequireNewInstance=True inside your both connection strings like:

     <connectionStrings>

       <add name="CRMConnectionString" connectionString="Url=orgname.crm.dynamics.com; Username=user@domain.onmicrosoft.com; Password=password; AuthType=Office365; RequireNewInstance=True;" />

     </connectionStrings>

  • Pradip Raj Profile Picture
    Pradip Raj 327 on at
    RE: How to use two CrmServiceClient to connect with two CRM instances?

    Sorry its my mistake.

    Correct one :

    CrmServiceClient conn2 = new CrmServiceClient(ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString);

    Both the instances connection strings are added in web.config.

    All the instances for both the organization are different. Still not able to insert in second instance.

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: How to use two CrmServiceClient to connect with two CRM instances?

    Am I right that you use the same connection string for both connections - ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString

    The same connection string means the same organization to work with. Correct me if I wrong.

  • Pradip Raj Profile Picture
    Pradip Raj 327 on at
    RE: How to use two CrmServiceClient to connect with two CRM instances?

    Code :

    IOrganizationService _orgService;

    1)

    CrmServiceClient conn = new CrmServiceClient(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

     _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

    2)

    IOrganizationService _orgService2;

    CrmServiceClient conn2 = new CrmServiceClient(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

     _orgService2= (IOrganizationService)conn2.OrganizationWebProxyClient != null ? (IOrganizationService)conn2.OrganizationWebProxyClient : (IOrganizationService)conn2.OrganizationServiceProxy;

    I am fetching data from first instance then inserting(creating) in another instance.

    orgService2.Create(entity); // entity is a collection of records.

    Let me know if you need any further information.

    Thanks,

    Pradip

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: How to use two CrmServiceClient to connect with two CRM instances?

    I meant what I meant.

    Can you please provide code that you use to instantiate CrmServiceClient instances?

    And my name is Andrii. Not Andri.

  • Pradip Raj Profile Picture
    Pradip Raj 327 on at
    RE: How to use two CrmServiceClient to connect with two CRM instances?

    Hi Andrii,

    you want me to set "useUniqueInstance=true" in CrmServiceClient constructor . Right?

    Thanks,

    Pradip

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: How to use two CrmServiceClient to connect with two CRM instances?

    Hello,

    Try to add RequireNewInstance=True to connection string you use in constructor of CrmServiceClient

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans