Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Cannot connect to two different organizations on one class

(0) ShareShare
ReportReport
Posted on by 5

Hello everyone, we are having a brand new issue. Until about the 1st of this month we were able to connect to two different CRM online organizations on the same console application where we take certain data from one and do work on the other org. 

When we connect to organization 1, and then we try to connect to organization 2 the CrmServiceClient object stays pointing at organization 1. For example:

private static void test()
{
CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRMCloudProd"].ConnectionString);
Console.WriteLine(crmSvc.ConnectedOrgFriendlyName);

Prints our production environment

usertest2();

}
private static void test2()
{
CrmServiceClient crmSvc2 = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRMCloudSandbox"].ConnectionString);
Console.WriteLine(crmSvc2.ConnectedOrgFriendlyName);

Prints our production environment still 
}

If we flip it, so that CRMCloudSandbox is the first CRM being pointed to, both functions will print Sandbox environment

Before this month, we were able to make use of both environments in the same class.

My questions is: is this a bug or an intended change? If this is intended; how could I interact between the two environments again? use two different classes?

  • Djmendez55 Profile Picture
    Djmendez55 5 on at
    RE: Cannot connect to two different organizations on one class

    Thank you! this was it

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Cannot connect to two different organizations on one class

    Hi,

    You need to add below setting in your connection string -

    RequireNewInstance=true

    crmtipoftheday.com/.../

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Djmendez55 Profile Picture
    Djmendez55 5 on at
    RE: Cannot connect to two different organizations on one class

    Update:

    I tried using the Dispose() method:

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

               Console.WriteLine("1: " + crmSvc.ConnectedOrgFriendlyName);

               crmSvc.Dispose();

               Console.WriteLine("2: " + crmSvc.ConnectedOrgFriendlyName);

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

               Console.WriteLine("3: " +crmSvc.ConnectedOrgFriendlyName);

    but would print out the same issue:

    1: Production

    2:

    3:  Production

    again if we tried them the other way around

    1: Sandbox

    2:

    3: Sandbox.

    I also tried putting the second function on a separate namespace and class, that did not work either.

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