SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to get two User Profiles service application

  • 1). User profile service1
  • 2). User profile service2

I have some code which only fetches the Ist User profile service application but not the second one. How can I access the 2nd User profile Service application using code?

SPServiceContext oServiceContext = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);
UserProfileManager oProfileManager = new UserProfileManager(oServiceContext);

Note: For some reason both User Profiles Service applications are provision on same SharePoint farm.

Note: No out of the box sync is used for User profiles.

share|improve this question
Why would you want two? Should the run on different servers? – Benny Skogberg Dec 11 '12 at 14:51
It's a requirement for the client to have the two user profiles on same SharePoint farm. – Geek Dec 11 '12 at 14:53
Note: no out of the box sync is used for User profiles. – Geek Dec 11 '12 at 14:54
Note: no out of the box sync is used for User propfiles. – Geek Dec 11 '12 at 14:54
up vote 2 down vote accepted

If you are having two User profile aervice applications in your farm then you need to create one custom connection group for each Web application in the farm. Then, you can change the each User profile service application to be associated with different Web application. It can be done by changing the service applications that are included in the Default service application connection group. In the code, use url of each Web application to get UserProfileManager of each User profile service application

share|improve this answer
It's rather proxy group that is attached to the Web Application, and this is how availability of different Service Applications in Web Application is managed. – Maksymilian Mulawa Dec 14 '12 at 11:58
I did this scenario a long time ago. Thanks for correction – Falak Mahmood Jan 6 '13 at 16:58

Though I agree that having 2 user profile services on a farm is a little nutty, hopefully your site only has 1 associated with it. You can GetContext on a SPSite object, instead of Default, which should get you the UPS associated to that site. If there's 2 associated... well... I'll have to dig in some more. Let me know if this works.

share|improve this answer
appreciate your help! – Geek Dec 14 '12 at 8:43

User Profile Service application will have it's proxy. This will let you distinguish these two services. Assign each proxy to a different proxy group (one could stay in the default group) and second you could assign to 'MyCustomGroup'. This is how you can create it.

New-SPServiceApplicationProxyGroup –Name MyCustomGroup

Now you can go to Central Administration->Application Management->Configure service application associations and assign your new proxy group to the web application. Assign one of the User Profile Service applications proxies to it. And now you are ready to roll.

And this is how you can retrieve Service application context using custom proxy group name.

 SPServiceApplicationProxyGroup applicationProxyGroup =   SPFarm.Local.ServiceApplicationProxyGroups["MyCustomGroup"];
 SPServiceContext serviceContext = SPServiceContext.GetContext(applicationProxyGroup, SPSiteSubscriptionIdentifier.Default);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.