Error: There is a compatibility range mismatch between the Web server and database

There is a compatibility range mismatch between the Web server and database “SP2013_Content_InsertDatabaseNameHere”, and connections to the data have been blocked to due to this incompatibility. This can happen when a content database has not been upgraded to be within the compatibility range of the Web server, or if the database has been upgraded to a higher level than the web server. The Web server and the database must be upgraded to the same version and build level to return to compatibility range.

error-after-sp1-upgrade

 

Cause

Discovered the error the first time I tried to upgrade a sandboxed solution within the selected database using PowerShell after upgrading to SP1. The error message appears the script output, Event Viewer and ULS. All databases had “No action required” as upgrade status, so this wasn’t the problem in my case. Hidden behind this error it appeared that insufficient database permissions was the cause.

Solution

It turned out that the logged in users’ permissions for this database had been lost after upgrading SharePoint 2013 from March PU to SP1 for some reason.

Fixed this was easy by adding the “SPDataAccess” role back to the user for the content database that was failing.

Adding comments, likes and follow from Yammer into you own SharePoint solutions

With the Yammer Embed API adding comments, likes and follow content is quite easy to achieve. Using this embed API has a great benefit as it is developed and maintained by Yammer, and will require very little effort to integrate. Features beyond the actions (like and follow) and the feed (comments) can be accomplished with either the REST or JavaScript API, but this will require more effort (reference: https://developer.yammer.com/yammer-sdks/). Integrating Yammer requires an external JavaScript file to be referenced, one or more placeholders (HTML div-tags) and local JavaScript function call to the API to initialize the integration.

Example of a news article based on a Page Layout in SharePoint Online with like, follow and comments from Yammer:

yammer-sp2013-onpremises-1

Embed API reference

</p>
<script type="text/javascript" src="https://assets.yammer.com/assets/platform_embed.js"></script></p>

Comments Feed

Comments can be made for many types of activities, in this example “page”. Yammer can maintain the relationship between the article and the feed either automatic by the URL in the browser, or it can be set explicit to ensure that the ID is unique. The first event on this article will trigger Yammer to create a activity page. This page can be enhanced with further metadata like a description and an image.

Example how this is displayed in SharePoint:

yammer-sp2013-onpremises-2

  Example how this is displayed in the  Yammer feed: yammer-sp2013-onpremises-3

Example on a activity page in Yammer:

yammer-sp2013-onpremises-4

Example code


<div id="yammer-page-feed" style="height:400px;width:500px;"></div>

<script>

yam.connect.embedFeed({

container: '#yammer-page-feed'

, network: 'o365.areflyen.no'

, feedType: 'open-graph'

, feedId: ''

, config: {

use_sso: true

, header: false

, footer: false

, showOpenGraphPreview: false

, defaultToCanonical: false

, hideNetworkName: false

, promptText: 'Comment on this article'




}

, objectProperties: {

url: ''

, type: 'page'

}

});

</script>

Like button

The practical effect of the “Like” action is limited. The button only shows the state for the current user (Like/Liked) and generates an activity. No total count of likes is available. When a user likes a page, it will also automatically be followed.

yammer-sp2013-onpremises-5

Example code


<div id="yammer-like"></div>

<script>

yam.connect.actionButton({

container: "#yammer-like",

network: "o365.areflyen.no",

action: "like"

});

</script>

Follow button

When following a page, you will subscribe to the activities on the current page. If you make a comment you will automatically follow the page.

yammer-sp2013-onpremises-6

Example code


<div id="yammer-like"></div>

<script>

yam.connect.actionButton({

container: "#yammer-follow",

network: "o365.areflyen.no",

action: "follow"

});

</script>

Summary

Yammer gives us easy to use API to make the switch from SharePoint Social to Yammer possible. Even if these examples are demonstrated in SharePoint Online, the same solution can be applied to On-Premises. Gaining the best user experience On-Premises will be by implementing a Single Sign-On (SSO) solution between you local network and Yammer. Disclaimer: Both SharePoint and Yammer is in continuous development, and the API and user interface shown in the screenshots have changed from the time this post was written.

Use PowerShell to create a demosite for all the common used Web Templates in SharePoint 2013

In my previous article I provided a list of all the common used web templates in SharePoint 2013. For demo purposes it can be handy to spin up a copy of all these templates and later easy remove them. Using PowerShell we can accomplish this with the snippets provided below. Change the parameters under “Configuration” to match your own environment.

Create new site collections

This snippet will create a new site collection for each of the web templates.


Add-PSSnapin Microsoft.SharePoint.PowerShell

# Configuration
$webApp = "http://intranet.contoso.com"
$managedPath = "sites"
$siteOwner = "contoso\sp_admin"
$languageId = 1033

# Create site collections for demo
Write "Create demo sites"
Start-SPAssignment -Global
New-SPSite "$webApp/$managedPath/demo-team-site" -Name "Team Site" -Template "STS#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-blog" -Name "Blog" -Template "BLOG#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-dev-site" -Name "Developer Site" -Template "DEV#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-project-iste" -Name "Project Site" -Template "PROJECTSITE#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-community-site" -Name "Community Site" -Template "COMMUNITY#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-document-center" -Name "Document Center" -Template "BDR#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-ediscovery-center" -Name "eDiscovery Center" -Template "EDISC#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-records-center" -Name "Records Center" -Template "OFFILE#1" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-bi-center" -Name "Business Intelligence Center" -Template "BICenterSite#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-ent-search-center" -Name "Enterprise Search Center" -Template "SRCHCEN#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-mysite-host" -Name "My Site Host" -Template "SPSMSITEHOST#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-community-portal" -Name "Community Portal" -Template "COMMUNITYPORTAL#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-basic-search-center" -Name "Basic Search Center" -Template "SRCHCENTERLITE#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-visio-process-rep" -Name "Visio Process Repository" -Template "visprus#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-pub-portal" -Name "Publishing Portal" -Template "BLANKINTERNETCONTAINER#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-ent-wiki" -Name "Enterprise Wiki" -Template "ENTERWIKI#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-prod-catalog" -Name "Product Catalog" -Template "PRODUCTCATALOG#0" -OwnerAlias $siteOwner -Language $languageId
Stop-SPAssignment -Global

Clean up and remove all the sites

This snippet will delete all the site collections created with the snippet above.


# Configuration
$webApp = "http://intranet.contoso.com"
$managedPath = "sites"
$siteOwner = "contoso\sp_admin"
$languageId = 1033

# Remove site collections
Remove-SPSite "$webApp/$managedPath/demo-team-site" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-blog" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-dev-site" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-project-site" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-community-site" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-document-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-ediscovery-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-records-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-bi-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-ent-search-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-mysite-host" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-community-portal" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-basic-search-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-visio-process-rep" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-pub-portal" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-ent-wiki" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-prod-catalog" -Confirm:$false

Summary

This article demonstrated how easy we can create a copy of all the common used web templates in SharePoint for demo purposes, and later clean it up.

Commonly used Web Templates in SharePoint 2013 with screenshots

I created a list of all the common used web templates in SharePoint 2013 with a screenshot showing how the site looks out-of-the-box primary to have for my own reference, but thought it might be interesting for other to access to so I posted this as an article.

This is the web templates available when creating new site collections through Central Admin with SharePoint 2013 Enterprise SP1. As many know there are lots of more templates, but these are the ones common available, and I recommend to stick to these when building solutions.

Please feel free to copy the screenshots for your own use.

Collaboration

Name

WebTemplateId

Screenshot

Team Site

STS#0

Team Site

Blog

BLOG#0

 Blog

Developer Site

DEV#0

 Developer Site - DevHome

Project Site

PROJECTSITE#0

 Project Site

Community Site

COMMUNITY#0

 Community Site - Community Home

Enterprise

Name

WebTemplateId

Screenshot

Document Center

BDR#0

 Document Center

eDiscovery Center

EDISC#0

 eDiscovery Center

Records Center

OFFILE#1

 Records Center

Business Intelligence Center

BICenterSite#0

 Business Intelligence Center

Enterprise Search Center

SRCHCEN#0

 Search - Enterprise

My Site Host

SPSMSITEHOST#0

 MySite Host

Community Portal

COMMUNITYPORTAL#0

 Community Portal

Basic Search Center

SRCHCENTERLITE#0

 Search - Basic

Visio Process Repository

visprus#0

 Visio Process Repository

Publishing

Name

WebTemplateId

Screenshot

Publishing Portal

BLANKINTERNETCONTAINER#0

 Publishing Portal

Enterprise Wiki

ENTERWIKI#0

 Enterprise Wiki

Product Catalog

PRODUCTCATALOG#0

 Product Catalog

 

Download all screenshots

Note: If you are using Office 365 please note that at the time this article was posted the “Product Catalog” is missing and a special version of the “Team Site” template is available.

Remove orphaned tasks from the aggregated task list on MySite in SharePoint 2013

For some reason a deleted task was still visible in the aggregated task list for a end-user. The task itself had been deleted from the source site, so when you clicked the task you got an error message telling you it did not exist anymore. The problem was that SharePoint was unable to remove the task from the aggregated view, so now we had to deal with a ghost task!

Solution

The new task aggregation is performed with the help of the Service Application “Work Management Service”, and the users MySite. When the service has aggregated your tasks, it stores the data itself in a list called “WmaAggregatedList_User”. Since it is a traditional list,  you might think: “This is easy! Just go to the list and delete the task!”. Sorry, but no. This list is only intended as a system list, and nothing we ever should care about, so it’s actually has no available views.

Step-by-step to remove the task

  1. Start “SharePoint Manager 2013” on one server in the farm (download from CodePlex)
  2. Navigate to the correct web application, and locate the users MySite site collection under “/personal” or your preferred managed path.
  3. Expand the structure and locate the list “WmaAggregatorList_User”, and choose to browse the “GridView”. If the user doesn’t have to many tasks, you should now be able to use this to visualy inspect the data.
  4. Locate the column named “TxEditUrl” and verify that it matched the URL of the ghost task. In my case I ignored the “&source=” end of the URL. Make a note of the list item ID for the task (the first column)
  5. Fire up good old “SharePoint 2013 Management Shell” to do some PowerShell magic.
  6. Example how to locate the task and remove it:

# Open the users personal site colletion and retrieve the list
$web = Get-SPWeb "http://mysite/personal/adamb"
$list = $web.Lists["WmaAggregatorList_User"] 

# Get the task with the ID located with SharePoint Manager
$item = $list.GetItemById(1) # NOTE: Use the correct ID here

# Now delete the task
$list.Items.DeleteItemById(1)

Summary

In some very rare cases, you can end up with users having orphaned tasks in their aggregated task list on MySite. I never got a understanding why this happened, but it was possible to remove this and get thing back to normal.

Add web parts from the gallery in SharePoint by code

For some reason I have never until now needed to add web parts to a page from the gallery using code. Why would I ever do this? The code runs inside a Feature Receiver, and is executed when creating new sites. The web part had been extended from a standard Content by Query Web Part (CBWP) with no code, and for that reason it was not possible to reference a unique class. So for this rare case I ended up with creating a utility function I thought was nice to share.

Function to add web parts from gallery


private static WebPart AddWebPartFromGallery(SPWeb web, SPLimitedWebPartManager wpm, string webPartFilename)
{
	string errorMessage;

	var query = new SPQuery
	{
		Query = String.Format(CultureInfo.CurrentCulture,
			"<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>{0}</Value></Eq></Where>",
			webPartFilename)
	};

	var webPartGallery = web.IsRootWeb ? web.GetCatalog(SPListTemplateType.WebPartCatalog) : web.Site.RootWeb.GetCatalog(SPListTemplateType.WebPartCatalog);
	var webParts = webPartGallery.GetItems(query);
	XmlReader xmlReader = new XmlTextReader(webParts[0].File.OpenBinaryStream());
	var webPart = (WebPart) wpm.ImportWebPart(xmlReader, out errorMessage);

	if (!string.IsNullOrEmpty(errorMessage))
		throw new ApplicationException("Error importing Web Part (" + webPartFilename + "): " + errorMessage);

	return webPart;
}

How to use the function

This example code shows how to retreive the web part manager, checkout the file, add the web part and finally publish it again.


// Get web and its web part manager
var web = new SPWeb("http://intranet.contoso.com");
var pagesLibraryName = SPUtility.GetLocalizedString("$Resources:List_Pages_UrlName", "cmscore", web.Language);
var file = web.GetFile(web.Url + "/" + pagesLibraryName + "/" + "default.aspx");
file.CheckOut();
var wpm = web.GetLimitedWebPartManager(web.Url + "/" + pagesLibraryName + "/" + "default.aspx", PersonalizationScope.Shared);

// Get the web part from the sites gallery
var customWebPart = AddWebPartFromGallery(web, wpm, "CustomWebPart.webpart");

// Add the web part to the page and publish the page
wpm.AddWebPart(customWebPart, MyZoneId, 1);
wpm.SaveChanges(customWebPart);
file.CheckIn("Checked in by feature");
file.Publish("Published by feature");

Summary

Retrieving and adding web parts from the web part gallery by code is more complex than utilizing web parts you can access by their class. This post shows you how to retrieve the web part from the gallery and add it to a web part zone within a standard publishing page.