The operation failed because the server could not access the distributed cache, Sharepoint 2013

This is related to Sharepoint 2013 news feed. Most common  root cause;

  1. User Profile application pool account not having the full permission over User Profile Service Application.
  • One possiblity is User Profile application pool running account expiration.

Error Message:

SharePoint returned the following error: The operation failed because the server could not access the distributed cache. Internal type name: Microsoft.Office.Server.Microfeed.MicrofeedException. Internal error code: 55. Contact your system administrator for help in resolving this problem.

Refer this URL for microfeed “Internal error” codes, deciphered for any other error codes .

First go to the Centra Administration -> Userprofile service via browser and check the permissions. Then Open the IIS manager and go to the App pools. Identify the App pool account which is running the service applications.  Try re- enter credentials to verify that the account is not expired. If not compare the UPS permission list contains the app pool admin account or not. If not do 2nd step. or else try rebuild Distributed Cache and give permission again. (step 1 and 2 ).

Please Read my previos post to understand what is Distributed Cache.

1).

# Check  cache 
Use-CacheCluster
Get-CacheHost

# Rebuilding Distributed Cache
Remove-SPDistributedCacheServiceInstance
$SPFarm = Get-SPFarm
$cacheClusterName = “SPDistributedCacheCluster_” + $SPFarm.Id.ToString()
$cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local
$cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName);
$instanceName =”SPDistributedCacheService Name=AppFabricCachingService”
$serviceInstance = Get-SPServiceInstance | ? {($_.Service.Tostring()) -eq $instanceName -and ($_.Server.Name) -eq $env:computername}
$serviceInstance.Delete()
Add-SPDistributedCacheServiceInstance

Get-CacheHost

 

2).

#Grant permission to UP app pool account to access UPS

$account = New-SPClaimsPrincipal <domain>\<username> -IdentityType WindowsSamAccountName
$UPA = Get-SPServiceApplication <UPS App ID>
$sec = Get-SPServiceApplicationSecurity $UPA
Grant-SPObjectSecurity $sec -Principal $account -Rights “Full Control”
Set-SPServiceApplicationSecurity -Identity $UPA -ObjectSecurity $sec

You can achive the same by using Central administration -> Manage services -> User Profile Service -> Permission (Grant full control )

 

Advertisements

Understanding Sharepoint 2013 Distributed Cache Service, Microblogs and feeds

All started with the new sharpoint 2013 newsfeed web part. Suddenly it displayed me an error message saying;

“The operation failed because the server could not access the distributed cache. Internal type name: Microsoft.Office.Server.Microfeed.MicrofeedException. Internal error code: 55. Contact your system administrator for help in resolving this problem

Then I had to understand what is Distributed Cache first. Here’s what i’ve gone through, from its design to configurations and finally some known issues. From the bottom line what Distributed Cache (DC) does is, it enables cacheing functionality for some key sharepoint features including;

  • Newsfeeds
  • Authentication
  • OneNote client access
  • Page load performance
  • Security Trimming

Mainly microblog features and feeds are rely on the DC to store data for very fast retrieval across all entities. The Distributed Cache service is built on Windows Server AppFabric, which implements the AppFabric Caching service.

The Architecture – How social feeds works with Distributed Cache

Original Image Link

Activities are posts and replies that can be either user-generated or system-generated. There are several types of activities in SharePoint Server 2013. These include the following:

  • Microblog activities   This includes posts, replies, likes, mentions, or tagging an item.
  • Following activities   This includes when a user follows people, documents, sites, or tags.
  • User profile activities   This includes birthday, job title change, anniversary, updates made to Ask Me About, creating a new blog post, or posting on a Community Site.
  • Document activities   This includes when a document is edited or a document is shared.

In SharePoint Server 2013, the newsfeed (or just simply the feed) displays activity information to users. Users access the feeds from a user’s My Site. In SharePoint Server 2013, a user’s My Site has several feeds available from which to choose. These different feeds show different views of activity information by filtering or pivoting on activity metadata. The different feeds available to users from their My Sites include the following:

  • Newsfeed   This is the default view when visiting a user’s My Site. The Newsfeed contains recent activities from followed entities. The Newsfeed displays 20 items and is sorted in reverse chronological order. Items listed in the Newsfeed are activities from entities a user follows, and conversations from any site feeds the user follows. Site feeds are explained later in this article.
  • Everyone   The Everyone feed shows the last 20 posts or replies across all users. The distinction between the Everyone feed and the Newsfeed is that theNewsfeed only shows activities from entities the user is following.
  • Activities   The Activities feed shows all activities associated with a user, including system-generated activities. The Activities feed represents the most accurate view of a user’s activities because it shows all activities and not just recent activities, which occurs with the Newsfeed. This feed is also seen when users browse to their profile or About Me page for a user.
  • Mentions   The Mentions feed for a user displays all posts or replies where that user was mentioned.
  • Likes   The Likes feed displays a list of posts or replies that the user has liked. This is not related to the I Like It feature from SharePoint Server 2010.
  • Site feeds   Activities are publicly accessible unless the activity refers to content that the user does not have access to. If feed functionality is required for a restricted group of users, a site feed should be used. Site feeds display posts and replies among the users of the group. Site feed posts and replies display in the Newsfeed of a user only if the user has access to the site feed. Site feeds do not display system-generated activities. By default, the site feed feature on a team site is enabled.

The microblog features and feeds rely on the following two caches: the Last Modified Time Cache and the Feed Cache.

  • Feed Cache   The Feed Cache stores recent activities and recent conversations for all entities
  • Last Modified Time Cache   The Last Modified Time Cache is used to determine the last modified time for all items in the Feed Cache.

Click here for full article

Considerations when implementing Distributed Cache

  • An administrator can allocate memory to the Distributed Cache. This allocation significantly affects the performance of the Distributed Cache service
  • Consider using a dedicated Distributed Cache server when you use the newsfeed and microblog features.
  • If you are using custom applications in SharePoint Server 2013 which use the AppFabric client APIs, or are creating custom caches, you should create a separate AppFabric cache cluster to support your custom applications. Do not use the AppFabric cache cluster supporting your SharePoint Server 2013 farm. Run your separate AppFabric cache cluster for your custom applications on separate servers from the servers dedicated to your SharePoint Server 2013 farm.
  • In a SharePoint Server 2013 farm, there must be at least one cache host running the Distributed Cache service.
  • On a server that has more than 16 GB of total physical memory, allocate a maximum of 16 GB of memory to the Distributed Cache service. If you allocate more than 16 GB of memory to the Distributed Cache service, the server might unexpectedly stop responding for more than 10 seconds.

More about planning for the Distributed Cache service, http://technet.microsoft.com/library/jj219572(office.15).aspx

Refer this for managing the Distributed Cache service, http://technet.microsoft.com/library/jj219613(office.15).aspx

Warning – Important Safety Tip

  1. Do not administer the Distributed Cache through the Service window in Administrative Tools under Control Panel, or through the AppFabric for Windows Server application on the Start menu. This could get the Distributed Cache service into a state where you might need to rebuild your farm.
  2. Microsoft recommends you avoid starting a Distributed Cache service instance on servers that are already running SQL Server, Search, Excel Services or Project Services.
  3. If you plan to have more than one Cache Host, the first server added should be configured to allow inbound ICMPv4 traffic.
  4. The right way to start the service is with the Add-SPDistributedCacheServiceInstance PowerShell cmdlet. You run this on a SharePoint server you would like to add to your Cache Cluster, which makes the current server a Cache Host. Simply stopping the service instance would cause the contents of the cache on that server to go missing, degrading performance.

Some common issue related to Distributed Cache

  • Sharepoint 2013 Newsfeed does not display feeds, follows, everyone etc.

References:

http://blogs.technet.com/b/uktechnet/archive/2013/05/07/guest-post-distributed-cache-service-in-sharepoint-2013.aspx

http://technet.microsoft.com/en-us/library/jj219613.aspx

Yammer or Sharepoint for Document Collaboration

With SharePoint and Yammer integration roadmap advancing, and Microsoft’s advice is clear (Go Yammer!), customers and would-be customers of both products are recognizing overlaps in functionality and asking questions around how the two products could (and should) run side-by-side.

The inconvenient truth, at this stage, is that there is no one-size-fits-all answer. How organisations use the platforms side-by-side will depend on a range of unique factors, such as current adoption and levels of customization. Underpinning any strategy should be a solid understanding of the technical scope of each product, and where that scope overlaps.

By  on July 19th, 2013.

what is parallel execution in PLINQ ?

I got this  blog once i was surfing the internet for new features in .NET 4.5. This is something interesting about PLINQ queries and its behaviours. As the title says “it’s not always guaranteed that your query is always executed parallelly”.

Yes, You may think that AsParallel() method runs in parallel for query with much faster and with increased performances.  By default, PLINQ prefers to use a simple sequential algorithm over a potentially expensive parallel algorithm, and so some queries will execute sequentially, especially queries where the chain of operators do not lend themselves to parallelism. PLINQ’s intent is to run your queries as fast as possible, so if there’s a good likelihood that the complexities of parallelism will slow it down, PLINQ will perform the query sequentially rather than in parallel.

In .NET 4.5, PLINQ’s algorithms have improved over .NET 4.0 such that its set of parallelizable queries has broadened and substantially fewer queries fall back to sequential execution.  In .NET 4.0, in order to force PLINQ to use a parallel algorithm, user can call;

WithExecutionMode(ParallelExecutionMode.ForceParallelism);

But in .NET 4.5 the query executes is in parallel, even without the WithExecutionMode hint.

Sequential Fallback in .NET 4 and .NET 4.5

One way to illustrate the improvements to the sequential fallback is to look at the list of operators that may cause the query to fallback to sequential. Whether or not the operator actually causes a sequential fallback depends on other operators in the query as well.

Operators that may cause sequential fallback in both .NET 4 and .NET 4.5 are marked in blue, and operators that may cause fallback in .NET 4 but no longer in .NET 4.5 are marked in orange.

PLINQ

So, in .NET 4.5, as long as the query does not contain positional operators or the ElementAt operator, it will not fall back to sequential.

Potential Risks of the Change

The fact that some queries used to execute sequentially and now execute in parallel opens up the possibility of exposing more latent race conditions in users’ code.

There is a bug in the query above: the delegate passed into the Select operator is not thread-safe. However, the query will still happen to work in .NET 4, because as an implementation detail PLINQ decides to execute the query sequentially. In .NET 4.5, the query will run in parallel, and so list.Add(x) could be called from multiple threads concurrently, potentially resulting in a corrupted List instance.

Please refer the original Post by gor Ostrovsky – MSFT here.

SharePoint DocumentSet vs Folders

Once i was thinking that DocumnetSet is same as a folder in SharePoint. So i did some readings and found this.

It says;

“There is a difference between a folder in SharePoint and a folder on your desktop. Microsoft made them look the same in the GUI to make it easier on users, but that’s where it stops. In SharePoint, a folder is simply a “view”. In other words, it is a way to limit the number of items the database displays. If you look at the URL, it’s a long complicated way of saying only show me the stuff assigned to this naming designation.

So if folders are views in SharePoint, why can’t I change them like views? You got me there. Somewhere along the line, the capabilities of the “folder” view and the “normal” view diverged and different rules applied. For example, I can add unique permissions to folders, but I can’t add column properties. The opposite is true for views.”

The point is in SharePoint 2010, Microsoft decided to change how it thought about Content Management. Since content types have caught on as the best way to solve the problem of “a single set of rules and naming conventions,” they started to think how they could exploit that scenario to group things together. THUS, the document set.

A document set is a group of related documents that can be created in one step and then managed as a single entity. A document set is not a view, but a special content type. It is managed and deployed from a site collection level. You can create custom document set content types with site columns and managed metadata. You can apply unique permissions to document sets. You can view a document set’s version history. You can trigger workflows within a document set.”

Here is the Complete article i’ve found.

Cheers…!!!

Unable to view uploaded documents in Sharepoint Meeting Workspace

This is something interesting. I’ve found this while I was developing an event management app. So apparently I was selected the Meeting Workspace Site Definition. The problem occurs when I was uploading a document to a document library. In here we can’t use SPFile.CopyTo();  So I used

SPSite site = SPContext.Current.Site;

SPWeb web = SPContext.Current.Web;
SPFile file = web.GetFile("/Shared%20Documents/Doc.docx");
using (SPWeb oWeb = site.OpenWeb(<siteURL>))
{
    SPList documentLibrary = meetingWorkspace.Lists["Document Library"];
    documentLibrary.RootFolder.Files.Add(file.Name, file.OpenBinary());
}
This code works fine, no issues. But if  you navigate to the document library, you can not NOT SEE any uploaded documents there(in view).  So what was happened to the document?  If you check the value of the SPList.RootFolder.Files.Count;  property you will see that the file is there too. So why does the Document Library keep saying that there are no items to display?
Here is the answer.
By default you can associate a Meeting Workspace with multiple Calendar Items. Every time you associate a Meeting Workspace with a Calendar Item, a new instance is being registered with the Meeting Workspace. In order to separate files that belong to different instances, SharePoint uploads them to separate folders. The confusing thing is, that although the instance folders are not being displayed in the UI, they are there.
So all we have to do is make sure to add the document into correct instance. Following is the workaround,

SPSite site = SPContext.Current.Site;

SPWeb web = SPContext.Current.Web;
string instanceId = "1";
SPFile file = web.GetFile("/Shared%20Documents/Doc.docx");
using (SPWeb meetingWorkspace = site.OpenWeb(<siteURL>))
{
    SPList documentLibrary = meetingWorkspace.Lists["Document Library"];
    SPFolder instanceFolder = documentLibrary.RootFolder.SubFolders[instanceId];
    instanceFolder.Files.Add(file.Name, file.OpenBinary());
}
Now Go back to the Library and check. Check this for more clarifications.
Good luck.

How to Bind Distribution List to Sharepoint Peoplepicker

I guess most of you aware of  how to use Sharepoint PeoplePicler control in your sharepoint solutions.If not here is a perfect blog http://karinebosch.wordpress.com/sharepoint-controls/peopleeditor-control/ i found while i was struggling. As it says we can bind either, User, SPGroup or SPSecurityGroup. But the real game starts when you are an amateur to Sharepoint and so badly wanted to bind a DL to Peoplepicker and use. So here is the way i came across.

Senario:

Add a DL using PeoplePicker and store it in a List. Then later get the users of the DL  (Eg: mail address etc.)

Solution:

First add the following Line to the Picker control. Note the Selection set.

<sharepoint:PeopleEditor ID="PeopleEditor2" runat="server" AllowEmpty="true" MultiSelect="true"
 SelectionSet="User,DL" CssClass="event-invite-ppl" />

Then add the following Code to determine whether it is a ‘User’ or a ‘DL’.

StringBuilder groupNames = new StringBuilder(string.Empty);
for (int i = 0; i < PeopleEditor2.Entities.Count; i++)
{
 PickerEntity pe = (PickerEntity)PeopleEditor2.Entities[i];
 if (pe.EntityType == "DL")
{
 groupNames.Append(pe.DisplayText);
 groupNames.Append(";");

}
 else if (pe.EntityType == "User")
  {
   SPFieldUserValue inviteetoadd = new SPFieldUserValue(oSPWeb, oSPWeb.EnsureUser(pe.Key).ID, pe.Key);
   inviteeListCollection.Add(inviteetoadd);
  }
}
newParticipantItem["InvitedGroupNames"] = groupNames.ToString();

Now have the Display Name of the DL. So we need to get the DL related to it and bind it to the PeoplePicker control.

if (participantListItem["InvitedGroupNames"] != null)
{
 string[] groupNames = participantListItem["InvitedGroupNames"].ToString().Split(';');
 groupNames = groupNames.Where(x => !string.IsNullOrEmpty(x)).ToArray();
 
foreach (string group in groupNames)
 {
   PickerEntity groupEntity = new PickerEntity();
   groupEntity.Key = GetADGroupName(groupName);
   entityArrayList.Add(groupEntity);
 }
}
 PeopleEditor2.UpdateEntities(entityArrayList);
 
---------------------------------------------------------------


string GetADGroupLoginName(string groupName)
 {
 string userNames = string.Empty;
 System.DirectoryServices.SearchResult result;
 DirectorySearcher search = new DirectorySearcher();
 search.Filter = String.Format("(cn={0})", groupName);
 result = search.FindOne();

 if (result != null)
 {
 userNames = result.Properties["samaccountname"][0].ToString();
 userNames = string.Format(@"<>\{0}", userNames);
 }
 return userNames;
 }

Using System.DirectoryService; //You will need to namespace 

If you need to get the names (Eg: Dayan Sameera) of the given DL users. Use the following method.

ArrayList GetADGroupUsers(string groupName)
 {
 System.DirectoryServices.SearchResult result;
 DirectorySearcher search = new DirectorySearcher();
 search.Filter = String.Format("(cn={0})", groupName);
 search.PropertiesToLoad.Add("member");
 result = search.FindOne();
 ArrayList userNames = new ArrayList();
 if (result != null)
 {
 for (int counter = 0; counter < result.Properties["member"].Count; counter++)
 {
 string user = (string)result.Properties["member"][counter]; 
 // here i needed to get only the name of the user,i used user.Substring();
 user = user.Substring(user.IndexOf("=") + 1, user.IndexOf(',') - 3);
 userNames.Add(user);
 }
 }
 return userNames;
 }

Note: Why i used the ‘Dispayname’ of the DL  ? Can we add the DL directly as a SPGroup and store ?  Please read this  and this.

Thanks.

Good luck