Tuesday, January 24, 2017

Problem with database collation change SQL Server



The Database could not be exclusively locked to perform the operation.
ALTER DATABASE failed. The default collation of database 'DatabaseName' cannot be set to "Collaction Name".  (Microsoft SQL Server, Error: 5030)




use master
go
ALTER DATABASE xxx SET SINGLE_USER WITH ROLLBACK IMMEDIATE
go
ALTER DATABASE xxx COLLATE yyyy
go
ALTER DATABASE xxx SET MULTI_USER
go




WARNING: this call to SET SINGLE_USER WITH ROLLBACK IMMEDIATE will disconnect anyone who might be connected to that database without warning, without chance of saving data! 

Monday, January 9, 2017

Delete all subsites (All Child Webs) - SharePoint 2013 and PowerShell

Error: There was a problem deleting Web site "/Subsite". Sites that have subsites or certain apps can't be deleted. Please try again after deleting all subsites and removing the apps.


Solution:
Run PowerShell command
 
 
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
Function Remove-ChildSites([Microsoft.SharePoint.SPWeb]$Web)
{
 Foreach($ChildWeb in $Web.Webs)
  {
  #Call the function recursively TO DELETE all sub-childs
  Remove-ChildSites($ChildWeb)
 }
    Write-host Removing web $Web.Url
  
    #Remove the web
 Remove-SPWeb $Web -Confirm:$false
}
 
$ParentWebURL="http://portal/site/"
 
#Get the Parent Web
$ParentWeb= Get-SPWeb $ParentWebURL
 
#Call the function to remove all child webs
Remove-ChildSites $ParentWeb