Category Archives: Database

Content databases contain orphaned Apps 1920x1080

Content databases contain orphaned Apps SharePoint 2013

Advertisements
Advertisements

Content databases contain orphaned Apps

SharePoint Health Analyzer rule “Content databases contain orphaned Apps.”

Some situation content database may become corrupted. The corrupted database may contain orphaned apps. Orphaned apps are not accessible, which causes unnecessary resource and license consumption and may result in failures in SharePoint upgrade.

Solution

Remove app for SharePoint instances from a SharePoint 2013 site.

A user must have the Manage Web site permission to remove an app for SharePoint. By default, this permission is only available to users with the Full Control permission level or who are in the site Owners group.

To remove an app from a SharePoint site

  • Verify that the user account that is performing this procedure is a member of the Site owners group.
  • On the site, on the Settings menu, click View Site Contents.
  • In the Apps section, point to the app that you want to remove, click “…”, and then click Remove.
  • Click OK to confirm that you want to remove the app.

To remove an app by using Windows PowerShell

Verify that you have the following memberships:

  • securityadmin fixed server role on the SQL Server instance.
  • db_owner fixed database role on all databases that are to be updated.
  • Administrators group on the server on which you are running the Windows PowerShell cmdlets.
  • Site Owners group on the site collection to which you want to install the app.

An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint 15 Products cmdlets. On the Start screen, click SharePoint 2013 Management Shell, type the following commands, and press ENTER after each one:

$instances = Get-SPAppInstance -Web
#Gets all apps installed to the subsite you specify.

$instance = $instances | where {$_.Title -eq ”}
#Sets the $instance variable to the app with the title you supply.

Uninstall-SPAppInstance -Identity $instance
#Uninstalls the app from the subsite.

At the question “Are you sure you want to perform this action?”,
type Y to uninstall the app.

Advertisements
Advertisements

Locate and remove app instances in all locations

An app for SharePoint in the App Catalog is available for users to install.Users can install apps for SharePoint on many sites. Below two Windows PowerShell scripts can be used to find all locations for a specific app and then uninstall all instances from every location.

First script to locate all instances of a specific app in a SharePoint environment. Then use the second script to uninstall all instances of the app from the SharePoint environment.

To locate specific apps by using Windows PowerShell (save as script and run script)

Verify that you have the following memberships:

  • securityadmin fixed server role on the SQL Server instance.
  • db_owner fixed database role on all databases that are to be updated.
  • Administrators group on the server on which you are running Windows PowerShell cmdlets.

An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint 2013 cmdlets

save the below script as “Get-AppInstances.ps1”

This Windows PowerShell script gets all app instances from your SharePoint 2013 farm for a specified App ID on a specified web application. You specify the App ID and the web application URL and the script will remove all of the instances of the App for all webs in that web application.

param(
[Parameter(Mandatory=$true)] [Guid] $productId,
[Parameter(Mandatory=$true)] [String] $webAppUrl
)

function GetAllInstances($productId = $null, $webAppUrl = $null)
{
$outAppName = "";
$sites = Get-SPSite -WebApplication $webAppUrl
$outWebs = @()
foreach($site in $sites){
if($site.AdministrationSiteType -ne "None"){
continue;
}
$webs = Get-SPWeb -site $site
foreach($web in $webs) {
$appinstances = Get-SPAppInstance -Web $web
foreach($instance in $appinstances) {
if($productId -eq $instance.App.ProductId) {
if ($outAppName -eq "") {
$outAppName = $instance.Title;
}
$outWebs += $web;
}
}
}
}
return ($outAppName,$outWebs)
}
Write-Host "This script will search all the sites in the webAppUrl for installed instances of the App."
$confirm = Read-Host "This can take a while. Proceed? (y/n)"
if($confirm -ne "y"){
Exit
}

$global:appName = $null;
$global:webs = $null;

{
$returnvalue = GetAllInstances -productId $productId -webAppUrl $webAppUrl;
$global:appName = $returnvalue[0];
$global:webs = $returnvalue[1];
}
);

$count = $global:webs.Count;
if($count -gt 0){
Write-Host "App Name:" $global:appName;
Write-Host "Product Id: $productId";
Write-Host "Number of instances: $count";
Write-Host "";
Write-Host "Urls:";

foreach($web in $global:webs) {
Write-Host $web.Url;
}
}
else {
Write-Host "No instances of the App with Product Id $productId found.";
}
return;
  • Now Open “SharePoint 2013 Management Shell”
  • Change to the directory where you saved the file.
  • At the Windows PowerShell command prompt, type the following command: 
./ Get-AppInstances.ps1 -productId -webAppUrl

To uninstall specific apps from all locations by using Windows PowerShell (save as script and run script)

Verify that you have the following memberships :

  • securityadmin fixed server role on the SQL Server instance.
  • db_owner fixed database role on all databases that are to be updated.
  • Administrators group on the server on which you are running Windows PowerShell cmdlets.

An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint 2013 cmdlets

save the below script as “Remove-App.ps1”

This Windows PowerShell script removes all app instances from your SharePoint 2013 farm for a specified App ID on a specified web application. You specify the App ID and the web application URL and the script will remove all of the instances of the App for all webs in that web application.

Advertisements
Advertisements
param(
[Parameter(Mandatory=$true)] [Guid] $productId,
[Parameter(Mandatory=$true)] [String] $webAppUrl
)

function RemoveInstances($productId = $null, $webAppUrl = $null)
{
$outAppName = "";
$sites = Get-SPSite -WebApplication $webAppUrl
$outWebs = @()
foreach($site in $sites){
if($site.AdministrationSiteType -ne "None"){
continue;
}
$webs = Get-SPWeb -site $site
foreach($web in $webs) {
$appinstances = Get-SPAppInstance -Web $web
foreach($instance in $appinstances) {
if($productId -eq $instance.App.ProductId) {
if ($outAppName -eq "") {
$outAppName = $instance.Title;
}
$outWebs += $web;
Write-Host "Uninstalling from" $web.Url;
Uninstall-SPAppInstance -Identity $instance -confirm:$false
}
}
}
}
return ($outAppName,$outWebs)
}

$confirm = Read-Host "This will uninstall all instances of the App and is irreversible. Proceed? (y/n)"
if($confirm -ne "y"){
Exit
}

$global:appName = $null;
$global:webs = $null;

{
$returnvalue = RemoveInstances -productId $productId -webAppUrl $webAppUrl;
$global:appName = $returnvalue[0];
$global:webs = $returnvalue[1];
}
);

$count = $global:webs.Count;
if($count -gt 0){
Write-Host "All the instances of the following App have been uninstalled:";
Write-Host "App Name:" $global:appName;
Write-Host "Product Id: $productId";
Write-Host "Number of instances: $count";
Write-Host "";
Write-Host "Urls:";

foreach($web in $global:webs) {
Write-Host $web.Url;
}
}
else {
Write-Host "No instances of the App with Product Id $productId found.";
}
return;
  • Open SharePoint 2013 Management Shell
  • Change to the directory where you saved the file.
  • At the Windows PowerShell command prompt, type the following command:
./ Remove-App.ps1 -productId -webAppUrl

If the issue still persists like as below

“If you have an orphaned app in the initialized state on a site and you delete the site, Health Analyzer reports that there's an error and the auto-fix doesn't work.”

Apply CU November 2016 which will 100% resolve the issue

SharePoint Server 2013 (KB3127933)
SharePoint Foundation 2013 (KB3127930)

Advertisements
Advertisements
Advertisements
Cannot connect to database master 1920x1080

Cannot connect to database master SharePoint 2016

Advertisements

Advertisements

Cannot connect to database master

While running psconfig wizard got error as "Cannot connect to database master at SQL Server at server_name. The database might not exist, or the current user does not have permission to connect to it"

Error:

"Cannot connect to database master at SQL Server at server_name. The database might not exist, or the current user does not have permission to connect to it" 

cannot-connect-to-database-master-at-server_sharepoint2016

Solution:

Open the Windows Firewall with Advanced Services and add an inbound rule to allow traffic over port 1433.

 

Advertisements

Advertisements

SQL Mirroring

Configure SQL Mirroring step by step

SQL Mirroring step by step

There are 3 different types of SQL Mirroring options available for use:

1. High Performance – Asynchronous (this requires the Enterprise Edition)

2. High Safety without Automatic Failover

3. High Safety with Automatic Failover (this requires a witness server running the same SQL version)

All three require roughly the same steps:

  1. Ensure the same login accounts are present on the Principal and the Mirror
  2. Backup the Principal DB and Logs
  3. Restore on the Mirror
  4. Configure the Mirroring Endpoints
  5. Set the partner on the Mirror
  6. Set the partner on the Principal (and the witness if necessary)

So lets work through the steps above……

Get our login’s in order

To get our accounts in order between our two servers we can run the following SQL script to give us an output to run on our mirror.

SELECT ‘create login [‘ + p.name + ‘] ‘ + case when p.type in(‘U’,’G’) then ‘from windows ‘ else ” end + ‘with ‘ + case when p.type = ‘S’ then ‘password = ‘ + master.sys.fn_varbintohexstr(l.password_hash) + ‘ hashed, ‘ + ‘sid = ‘ + master.sys.fn_varbintohexstr(l.sid) + ‘, check_expiration = ‘ + case when l.is_policy_checked > 0 then ‘ON, ‘ else ‘OFF, ‘ end + ‘check_policy = ‘ + case when l.is_expiration_checked > 0 then ‘ON, ‘ else ‘OFF, ‘ end + case when l.credential_id > 0 then ‘credential = ‘ + c.name + ‘, ‘ else ” end else ” end + ‘default_database = ‘ + p.default_database_name + case when len(p.default_language_name) > 0 then ‘, default_language = ‘ + p.default_language_name else ” end FROM sys.server_principals p LEFT JOIN sys.sql_logins l ON p.principal_id = l.principal_id LEFT JOIN sys.credentials c ON  l.credential_id = c.credential_id WHERE p.type in(‘S’,’U’,’G’) AND p.name <> ‘sa’ AND p.name NOT LIKE ‘##%’

Once executed run the output on the mirror server to create all the logins.

Backup the Primary and Restore on the mirror

We can run the below script on primary to take a file and log backup of all our user databases

DECLARE @name VARCHAR(4000) — database name DECLARE @path VARCHAR(4000) — path for backup files  DECLARE @fileName VARCHAR(4000) — filename for backup  DECLARE @logfileName VARCHAR(4000) — logfilename for backup  DECLARE @fileDate VARCHAR(20) — used for file name declare @sql nvarchar(4000)     SET @path = ‘C:SQLbackups’

SELECT @fileDate = ‘InitialMirror’

DECLARE db_cursor CURSOR FOR  SELECT name FROM master.dbo.sysdatabases WHERE name NOT IN (‘master’,’model’,’msdb’,’tempdb’)  –WHERE name NOT IN (‘master’,’model’,’msdb’,’tempdb’,’INCLUDE YOUR DB’s)’

CREATE TABLE #TEMPRESTORE ( CMD VARCHAR(400) ) OPEN db_cursor   FETCH NEXT FROM db_cursor INTO @name;        WHILE @@FETCH_STATUS = 0   BEGIN          SET @fileName = @path + @name + ‘_’ + @fileDate + ‘.BAK’         SET @logfileName = @path + @name + ‘_’ + @fileDate + ‘_Log.BAK’                              SET @sql = ‘ALTER DATABASE “‘ + @name + ‘” SET RECOVERY FULL’         exec sys.sp_executesql @sql;

BACKUP DATABASE @name TO DISK = @fileName with format;         BACKUP log @name TO DISK = @logfileName with format;                 INSERT INTO #TEMPRESTORE VALUES (‘RESTORE DATABASE “‘+@name+’”        FROM DISK = ”’+@fileName+”’ WITH NORECOVERY’)        INSERT INTO #TEMPRESTORE VALUES (‘go’)        INSERT INTO #TEMPRESTORE VALUES (‘RESTORE LOG “‘+@name+’”        FROM DISK = ”’+@logfileName+”’ WITH NORECOVERY’)          INSERT INTO #TEMPRESTORE VALUES (‘go’)        FETCH NEXT FROM db_cursor INTO @name   END

CLOSE db_cursor   DEALLOCATE db_cursor SELECT * FROM #TEMPRESTORE DROP TABLE #TEMPRESTORE

The output of this script will provide you with the restore commands to run on your mirror.  Just make sure you copy all the SQL backup files from the location specifed at the top of the script to the exact same location on your mirror.

Configure the mirror endpoints and setting up the mirror

Right click on a database you want to mirror

sql tasks mirror

sql tasks mirror

configuring database mirroring secirity wizard

configuring database mirroring secirity wizard

include withness server Database Mirroring

include withness server Database Mirroring

choose server to configure sqlmirror

choose server to configure sqlmirror

principal server instance sqlmirror

principal server instance sqlmirror

mirror server instance sqlmirror

mirror server instance sqlmirror

withness server instance sqlmirror

withness server instance sqlmirror

service account sqlmirror mirror

service account sqlmirror mirror

configuring endpoints sqlmirror

configuring endpoints sqlmirror

finish sqlmirror

finish sqlmirror

Configure further databases to mirror

You can either carryout the wizard above again or run the following script on the mirror.

DECLARE @name VARCHAR(4000) — database name  DECLARE @sql nvarchar(4000) DECLARE @mirrorendpoint varchar(4000)

SET @mirrorendpoint =’TCP://primaryserverFQDN:5022′ SET @name = ‘DatabaseNameToMirror’

SET @sql = ‘ALTER DATABASE “‘ + @name + ‘” SET PARTNER = ”’+@mirrorendpoint+”” exec sys.sp_executesql @sql;

then run this on the primary

DECLARE @name VARCHAR(4000) — database name

DECLARE @sql nvarchar(4000)

DECLARE @mirrorendpoint varchar(4000)

DECLARE @witnessendpoint varchar(4000)

SET @mirrorendpoint =’TCP://yourmirrorFQDN:5022′

SET @witnessendpoint =’TCP://yourwitnessFQDN:5022′

SET @name = ‘DatabaseNameToMirror’

SET @sql = ‘ALTER DATABASE “‘ + @name + ‘” SET PARTNER = ”’+@mirrorendpoint+”” exec sys.sp_executesql @sql; SET @sql = ‘ALTER DATABASE “‘ + @name + ‘” SET WITNESS = ”’+@witnessendpoint+”” exec sys.sp_executesql @sql;

Advertisements

Advertisements

new features

windows server 2016 new features

Below are windows server 2016 new features for reference. Go through the article for detail description […]

what are server roles and features in windows server 2016

This articles describes in details about what are server roles in windows server 2016 . […]

Windows Server 2016 Networking

Overview of Name Resolution in DNS Server DNS installation requirements Install DNS server role

previous arrow
next arrow

ArrowArrow

Shadow
Slider
Get Database Size 1920x1080

Get Database Size for all SharePoint Data Bases using PowerShell

Get Database Size for all SharePoint Data Bases using PowerShell

Add-PSSnapin microsoft.sharepoint.powershell

$size = 0

foreach ($db in Get-SPContentDatabase)

{

$size = $size + $db.DiskSizeRequired

}

$cdbs = “{0:N2}” -f($size/1gb)

$ssa = Get-SPEnterpriseSearchServiceApplication

$topo = $ssa | Get-SPEnterpriseSearchTopology  -Active

$indexcomponent = (Get-SPEnterpriseSearchComponent -SearchTopology $topo | ?{$_.name -like “*index*”})[0]

$folder = $indexcomponent.RootDirectory

$indexsize = “{0:N2}” -f ((Get-ChildItem $folder -Recurse | Measure-Object -sum  Length).sum/1GB)

$dbs = Get-SPDatabase

cls

write-host “————————————————————————————–” -fore green

Get-Date

write-host “”

write-host “————————————————————————————–” -fore green

write-host “SUM: Content DB Size in GB: ” -NoNewline -fore White

write-host $cdbs -fore Yellow

write-host “————————————————————————————–” -fore green

write-host “Index Size (Localhost) on Disk in GB: “-NoNewline -fore white

write-host $indexsize -fore Yellow

write-host “————————————————————————————–” -fore green

$sum_all_dbs = 0

foreach ($db in $dbs)

{

write-host $db.name “DB Size in GB: ” -NoNewline -fore White

$dsr = “{0:N2}” -f ($db.DiskSizeRequired/1gb)

write-host $dsr  -fore Yellow

$sum_all_dbs=$sum_all_dbs+$db.DiskSizeRequired

}

write-host “————————————————————————————–” -fore green

write-host “SUM: Usage of all SharePoint DBs in GB: ” -NoNewline -fore White

$sum_all_dbs = “{0:N2}” -f ($sum_all_dbs/1gb)

write-host $sum_all_dbs -fore Yellow

write-host “————————————————————————————–” -fore green