0

I am using following C# code to read user profile of users but getting error. Please ignore any syntax error in following code as I typed by hand here.

Code

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
   SPServiceContext context = SPServiceContext.GetContext(site);
   UserProfileManager profileManager = new UserProfileManager(context);
   foreach(UserProfile profile in profileManager)
   {
      Response.Write(profile[PropertyConstants.FirstName].Value);
   }
}

Error I am getting is An error was encountered while retrieving the user profile. Upon checking logs, I found some more errors as below.

Error

UserProfile.RetrieveUser() Exception (UserId = 'd6bea61f-5867-4cff-a941-5db00d025422'): System.Data.SqlClient.SqlException (0x80131904): Cannot continue the execution because the session is in the kill state. A severe error occurred on the current command. The results, if any, should be discarded.

GetUserProfile_RetrieveUser_DB Failure: RetrieveUser: Failed because of SQLException System.Data.SqlClient.SqlException (0x80131904): Cannot continue the execution because the session is in the kill state. A severe error occurred on the current command. The results, if any, should be discarded.

I have two SharePoint 2016 environments, Production and DR. The code works fine on Production but not on DR. Following are some facts about both environments.

  1. User Profile service application is configured on both environments. Active directory import is working and loading profiles on both environments.
  2. Search service application is not configured on both environments.
  3. MySites are not configured on both environments.
  4. Service accounts used to configure different service applications, services, application pools etc. are same on both environments

Yet the code works on one environment but not on other. What can I do to fix the issue?

1
  • Some more facts. Production environment where it works has SQL Server 2016 Standard. DR environment where it doesn't work has SQL Server 2019 (RTM) Enterprise. Commented Apr 29 at 4:56

1 Answer 1

0

This is due to bug in SQL Server 2019. Installing 5025808 Cumulative update 21 (CU21) for SQL Server 2019 fixed the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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