web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

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

  • Pradip Raj Profile Picture
    327 on at

    Hi Andrii,

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

    Thanks,

    Pradip

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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
    327 on at

    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
    84,331 Most Valuable Professional on at

    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
    327 on at

    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.

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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>

  • Verified answer
    Pradip Raj Profile Picture
    327 on at

    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

  • Vishal Giri Profile Picture
    15 on at

    Worked well.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans