Data Base Name too long

By default, SharePoint adds a GUID to the end of the database name. Here is the procedure on how to rename this long name. However, you need to create a back up. I have multiple tests on different scenario, I encounter so many issues. Fortunately, I have no only a back up data base, also I created a checkpoint in Hyper-V so, I can revert the change

Solution

1. Using PowerShell and Microsoft SQL Server Studio

 

  1. Dismount Database (Powershell)
  2. Modify Database name using MSSS
  3. Mount Database (Powershell)

 

$caURL = “http://sp2016:5555/”
$NewCaDbName= “SharePoint_CentralAdmin_GUID1232123123”
$caDB = Get-SPContentDatabase -WebApplication $caURL
$caDB

# 1. Detach data base:
$NumberCaDB = Get-SPContentDatabase -WebApplication $caURL | Measure
if ($NumberCaDB.Count -gt 1)
{Write-Output “Found more than one Data base on your collection site. You need to dismount or remove unused one”
exit}
elseif ($NumberCaDB.Count -eq 0)
{Write-Output “No Data base found”
exit}
else
{Dismount-SPContentDatabase $caDB.id -Verbose}

# 2. Rename data base via SQL Server Management Studio:

$step2Txt = “
Now, rename data base via SQL Server Management Studio:
1. Right click the database -> Properties -> Options -> Restricted Access -> Single User Mode -> ok
2. Right click the database -> Rename -> Enter new name
3. Right click the database -> Properties -> Options -> Restricted Access -> Multi-User -> ok “

$a = new-object -comobject wscript.shell
$intAnswer = $a.popup(“Dismount completed, now do the following: `n”, 0,”Dismount Completed”,0)

# 3 Mount data base
Mount-SPContentDatabase $NewCaDbName -DatabaseServer $cadb.Server -WebApplication $caURL
iisreset # Need to reset IIS

 

2. Using PowerShell

  1. Create a new Database
  2. Move current site content to a new created database

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$caURL = “http://sp2016:5555/”
$NewCaDbName= “SP_CA”
$DbaseServer = “sqlserver\sql”

#1. Create and assign new Dbase to a variable
$NewCaAdminContentDB = New-SPContentDatabase -Name $NewCaDbName -WebApplication $caURL

#2 Verify: You should only have 2 Content Databases.
Get-SPContentDatabase -WebApplication $caURL
$OldCaDb = Get-SPContentDatabase -WebApplication $caURL | select -Index 0
$NewCaDb = Get-SPContentDatabase -WebApplication $caURL | select -Index 1

#3. Move old dbase content to New dbase
Get-SPSite –ContentDatabase $OldCaDb.id | Move-SPSite –DestinationDatabase $NewCaDb.Id -Confirm:$false -Verbose
Get-SPContentDatabase -WebApplication $caURL

#4. Remove old dbase
$a = new-object -comobject wscript.shell
$ConfirmTXT = “CAUTIOUS! Please test you Central Admin connection now before proceeding `n”
$ConfirmTXT = $ConfirmTXT + “Confirm to remove old database? `n`n”
$ConfirmTXT = $ConfirmTXT + “NEW:`nName : ” + $NewcaDB.Name + “`nID : ” + $NewcaDB.id + “`n`n”
$ConfirmTXT = $ConfirmTXT + “OLD:`nName : ” + $OldCaDb.name + ” `nID : ” + $OldCaDb.id
$confirmRemoveDbase = $a.popup($ConfirmTXT, 0, “Completed”, 4)
if ($confirmRemoveDbase -eq 6)
{
write-host “Removing ..”, $OldCaDb.Name
Remove-SPContentDatabase -Identity $OldCaDb.Id -Confirm:$false -Verbose
Get-SPContentDatabase -WebApplication $caURL
}
else
{
Write-Host “Cancel removal ..”
exit
}