0

Getting below error while performing Restore-SPSite:

System.Data.SqlClient.SqlException (0x80131904): Violation of PRIMARY KEY constraint 'PK_SiteUrlMap'. Cannot insert duplicate key in object 'dbo.SiteUrlMap'. The duplicate key value is (0x, abc.pqr.com/xyz, 3). The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.SharePoint.Utilities.SqlSession.ExecuteNonQuery(SqlCommand command, SqlInfoMessageEventHandler handler) ClientConnectionId:82c5ef0d-e19f-4075-a9c0-0b850cb17795 Error Number:2627,State:1,Class:14

  • Does this apply: blog.mastykarz.nl/… – Per Jakobsen Mar 5 '18 at 14:44
  • I already went through this link but it didn't help. Option 1 is not feasible for me. I am using option 2 but getting same issue. – ARD Mar 6 '18 at 5:15
1

You didn't tell us what you want to achieve with your restore-operation. I assume you want to copy or rename an existing HostNamed SiteCollection (HNSC).

A HSNC can have different URLs assigned with the Set-SPSiteURL Command.

There are several possible solutions:

Option #1: remove all SPSiteUrls

The first option that you have is to remove all SPSiteUrls before performing the backup of the Site Collection. After having restored the site you would add the SPSiteUrls back and optionally would add some new SPSiteUrls to the copied Site Collection.

Although this approach is pretty straight-forward it has one serious disadvantage: by removing the additional SPSiteUrls from the original Site Collection you’re interrupting its operability and prevent some users from accessing it. And although this might be okay in some cases, there might be scenarios where this is simply not an option.

Option #2: remove all SPSiteUrls after the backup

An alternative approach would be to take a backup of the Site Collection, restore it in another Farm of exactly the same patch level, remove all SPSiteUrls there and then restore it back to the original Farm.

In this case no service interruption occurs in the original Site Collection. The only downside is the need for a separate Farm with exactly the same patch level as the original Farm where you can restore the Site Collection from the backup, remove all SPSiteUrls and create a new backup to restore to the original Farm.

Option #3: Directly rename the site without backup&restore

$site = Get-SPSite http://portal.contoso.com/sites/foo
$uri = New-Object System.Uri("http://foo.contoso.com")
$site.Rename($uri)

To get 100% success I have to force the Content Database to refresh its site map with this:

((Get-SPSite http://foo.contoso.com).contentdatabase).RefreshSitesInConfigurationDatabase

and run an IISReset. The IISReset isn’t always necessary, but it’s good to plan for it.

  • Hi MHeld, Thanks for reply. My requirement is to take backup of site from prod and restore it to pre prod. I cant choose option 1 as I cant remove site URL from Prod. Currently I am using 2nd Option for this activity but facing same issue. Option 3 is not applicable for me. – ARD Mar 6 '18 at 5:10
  • The error should only happen, if you already have a HNSC with the same SiteURL. Does the site already exist in an older version in PreProd? You could also try to get more information by directly reading content of the affected "dbo.SiteUrlMap" table in SQL Server (SELECT * from dbo.SiteUrlMap). You can find it in the SharePoint Configuration Database. WARNING: Do not modify anything directly in the database! You will instantly lose support on your farm. – MHeld Mar 6 '18 at 7:11
1

It is a bug to restore host name site collection , try to install security update to fix the problem :

https://support.microsoft.com/en-us/help/3141486/ms17-002-description-of-the-security-update-for-sharepoint-server-2016 .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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