Considerations while provisioning the service application using pre-created databases”there is already a database exists with the same name”

* Recently I had worked with my customer to setup a new SharePoint farm with pre-created (DBA created) databases.

Concept and prerequisites are very well documented inthis TechNet article. While testing the deployment what really matters were the creation of couple of service application. 

* Bad guys were Usage Logging & State Service Application. All other service applications were easy to provision (we were using auto AutoSPInstallerhttp://autospinstaller.codeplex.com/  to automate the deployment using Power Shell).

* Except Usage Logging & State Service application all other service applications were able to use the pre-created database while provisioning the new service application using New-SP* commandlets. 

* Usage Logging & State Service applications were complaining that the there is already a database exists with the same name

* To work-around this, we have to approach the provision in a different way. I’m giving the provisioning script samples for both Usage Logging & State Service Applications.

Usage Logging Service Application :

Steps are explaining below.

1. Create new Usage Service Application with a temporary ( or default) database

2. After that, modify the Usage Service Application to use the pre-created database name, this will dismount the usage logging database created in step #1

3. Delete the database created in step #1 manually from the SQL server

Automating the Steps 1-2 given below.

add-pssnapin microsoft.sharepoint.powershell

Write-Host -ForegroundColor White "Provisioning WSS Usage Application..."

$SPUsageApplicationName = "WSS Usage Service Application"
$precreatedUsageDB = "WSS_Usage_Database"
$sqlserver = "spsql"
$tempUsageDB = "WSS_Usage_ToDelete"

New-SPUsageApplication -Name $SPUsageApplicationName -DatabaseName $tempUsageDB

$UsageServiceApp = Get-SPUsageApplication $SPUsageApplicationName

Set-SPUsageApplication -Identity $UsageServiceApp.ID -DatabaseName $precreatedUsageDB -DatabaseServer $sqlserver

Write-Host -ForegroundColor White "Re-provisioning Health Data Collection Proxy as by default it will be in stopped state"

$SPUsageApplicationProxy = Get-SPServiceApplicationProxy | where {$_.DisplayName -eq $SPUsageApplicationName }
                                                                    $SPUsageApplicationProxy.Provision()

Write-Host -ForegroundColor Blue "Done provisioning SP Usage Application."

State Service Application :

This is little different than Usage Logging Service Application provisioning.

Steps are explaining below.

1. First we have to mount the pre-created database to SharePoint and have to initialize it.

2. Use the same method as other service application provisioning, using New-SPStateServiceApplication and provide the pre-created database name.

3. Create state service application proxy.

add-pssnapin microsoft.sharepoint.powershell

$StateServiceDB = "State_Service_DB"
$StateServiceName = "State Service Application"
$StateServiceProxyName = "State Service Application Proxy"

Write-Host -ForegroundColor White "Provisioning State Service Application..."

Mount-SPStateServiceDatabase -Name $StateServiceDB | Initialize-SPStateServiceDatabase

New-SPStateServiceApplication -Name $StateServiceName -Database $StateServiceDB | Out-Null

Write-Host -ForegroundColor White "Creating State Service Application Proxy..."

$StateServiceApplication = Get-SPStateServiceApplication -identity  $StateServiceName

$StateServiceApplication | New-SPStateServiceApplicationProxy -Name $StateServiceProxyName -DefaultProxyGroup

Write-Host -ForegroundColor Blue " - Done creating State Service Application."

Other service applications can be pointed in this scenario are

1. ASP.NET Session state service (Enable-SPSessionStateService). With that there is no way to specify a pre-created database , 

    ASP.NET session state database schema is provisioned by ASP.NET by calling SQLServices class. once you use Enable-SPSessionStateService.

From my deployment experience this was the main issue and there was no any other deployment issues faced while going with the DBA pre-created deployment method. Hope this hint will help someone.

Install & Configure SharePoint 2013 with SQL Client Alias

* Though this topic is very simple and highly recommended approach in the enterprise deployments, I have seen many deployments which are not following this approach. E.g.: Using SQL client alias for SharePoint installations will be really useful if you want move all databases to another SQL Server by just making alias change point to the new SQL server.

* In this post I’m going to cover how we can install & configure SharePoint 2013 Preview with SQL Client Alias. Though this post is talking about SharePoint 2013 preview, the underlying concept will be same for SharePoint 2010 & SharePoint 2013 RTM.

* In my test lab, I have total four virtual machines configured. This post is based on a SharePoint small server farm for setup and proof of concept. I will refer to this same environment in my future blog posts, there will be more servers adding to the existing server farm.

litdc : is the domain controller and AD server (domain : litware.local), this machine is installed with Windows 2008 R2 + SP1

litsql1 : is the SQL server machine which is installed with SQL Server 2012 RTM with Windows 2012 Server Release Candidate.

litsp1 : is the one of the SharePoint Servers, I’m configuring this server with WFE role. This server is installed with SharePoint Server 2013 Preview with Windows 2012 Server Release Candidate.

litsp3 : is the one of the SharePoint Servers, I’m configuring this server with Application role (central administration and other services). This server is installed with SharePoint Server 2013 Preview with Windows 2012 Server Release Candidate. Name of the server is litsp3 as I’m planning to add one more SharePoint Server litsp2 to with WFE layer later. 

In this post I’m only concentrating on the part of configuring SharePoint Servers with SQL Client Alias.

# Step 1

To harden the security for SQL server it is highly recommend to install SQL Server with named instance with custom port and block all default SQL specific ports. So, that is our first step to consider while setting up the SQL Server.

While installing the SQL Server in litsql1 server I have installed it with named instance “litsql1sql1”.

* After the installation of SQL Server with named instance, we have to assign a custom static port number for the SQL Service. You can do this in “SQL Server Configuration Manager”. 

* We have to configure it by taking the TCP/IP properties of “Protocols for SQL1 (SQL1 instance name)”. By default, whenever we install SQL Server with named instance it will assign a “TCP Dynamic Port”, we have to clear it out in the same location (just before TCP Port).

After doing the above step, we have to restart the “SQL Server Service” to use the newly assigned port.

To confirm the usage of the new port, you can either look at the SQL Server Logs in the SQL Server Managements studio or can look at the windows application event logs directly.

# Step 2

Once the above port validation is over the next important step is  open the custom port for In bound connections if you have firewall enabled. Just need to create a new Inbound Rule for allowing connections for the custom port, in my case it is  “65000”

# Step 3

Alright, now we can go to SharePoint side. 

* In my case there are two SharePoint Servers to be configured, one WFE – litsp1 and one Application Server – litsp3.

* Since I’m going to host central administration in litsp3

* I’m going to configure this server first. Main configuration needs only before running the PSConfig. * I have installed SharePoint 2013 Preview in both of these servers initially.

Before running the PSConfig , we have to configure the SQL Client Alias. There will be two versions of cliconfig in 64 bit operating system.

C:WindowsSystem32cliconfg.exe  – 64 bit version of cliconfig.exe

C:WindowsSysWOW64cliconfig.exe – 32 bit version of cliconfig.exe

SharePoint 2010 & 2013 are 64 based so we have to configure the 64 bit version of cliconfig.

C:WindowsSystem32cliconfg.exe

* In my test case I have created alias “spsql” with network library type “TCP/IP” (don’t use named pipes).
 
* In the Server Name textbox we have to give the SQL Server name (litsql1) and then uncheck the “Dynamically determine port” option and give the custom port number, in my case “65000”. After saving the changes you can validate the registry settings to make sure that it is applied correctly.

# Step 4

* At this point we are good to run SharePoint PSConfig and provision a new server farm.

* While creating a new farm, provide the SQL Client Alias “spsql” instead of the the SQL Server Instance name “litsql1sql1”.

* After finishing the PSCofig tasks, central administration site will be provisioned the SQL Server name will be used as “spsql”. 
* To connect other servers to the SharePoint farm we have to repeat step #3 in all servers. In my test lab I have one more server to be added to the same farm.

 

Configuring SQL Server client aliases

If you block UDP port 1434 or TCP port 1433 on the computer that is running SQL Server, you must create a SQL Server client alias on all other computers in the server farm. You can use SQL Server client components to create a SQL Server client alias for computers that connect to SQL Server.

To configure a SQL Server client alias

  1. Verify that the user account that is performing this procedure is a member of either the sysadmin or the serveradmin fixed server role.
  2. Run Setup for SQL Server on the target computer, and install the following client components:

Connectivity Components

Management Tools

  1. Open SQL Server Configuration Manager.
  • In the navigation pane, click SQL Native Client Configuration.

  • In the main window under Items, right-click Aliases, and select New Alias.

  • In the Alias – New dialog box, in the Alias Name field, enter a name for the alias. For example, enter SharePoint_alias.

  • In the Port No field, enter the port number for the database instance. For example, enter 40000. Make sure that the protocol is set to TCP/IP.

  • In the Server field, enter the name of the computer that is running SQL Server.

  • Click Apply, and then click OK.

  • Verification: You can test the SQL Server client alias by using SQL Server Management Studio, which is available when you install SQL Server client components.

  • Open SQL Server Management Studio.

  • When you are prompted to enter a server name, enter the name of the alias that you created, and then click Connect. If the connection is successful, SQL Server Management Studio is populated with objects that correspond to the remote database.

  • To check connectivity to additional database instances from SQL Server Management Studio, click Connect, and then click Database Engine.

  • See also :

    Securing SharePoint: Harden SQL Server in SharePoint Environments

    How to: Configure a Windows Firewall for Database Engine Access

    How to: Configure a Server to Listen on a Specific TCP Port (SQL Server Configuration Manager)