How to configure SQL Server Network Protocols in the SQL Server that houses BizTalk Server databases with PowerShell

Posted: April 4, 2013 in BizTalk, PowerShell
Tags: , , ,

Today is a special day for me, it’s my birthday, and I will continue the tradition of giving something to the community on this day (I started this tradition last year)… In the past I wrote a series of posts describing step by step how to install and configure BizTalk Server 2010.

One of this step is to configure SQL Server Network Protocols, in special ensure that TCP/IP is enable and Shared Memory is disable. You can see how to accomplish this using SQL Server Configuration Manager tool here.

However a community member (anonymous) left me a comment asking me whether it was possible to accomplish this (disable shared memory) from command line or registry and the answer is: YES, of course, you can for example configure all the SQL Server Network Protocols with PowerShell.

All network protocols are installed by SQL Server Setup, but may or may not be enabled. And you need to be aware that this protocols can have impact in your BizTalk Environment, for example:

  • Under certain stress conditions (such as clients accessing SQL Server from the same computer), the SQL Server Shared Memory protocol may lower BizTalk Server performance.
  • BizTalk Server loses connectivity with a remote SQL Server computer that houses the BizTalk Server databases and this may happen if the necessary protocols for SQL Server are not enabled.

So normally we need to perform the following configuration:

  • Disable the “Shared Memory” and “VIA” protocols
  • And Enable the “TCP/IP” and “Named Pipes” protocols
How can I configure SQL Server Network Protocols with PowerShell?

This is a simple script to configure SQL Server Network Protocols for SQL Server that houses BizTalk Server databases:

[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement")

##################################################################
# Function to Enable or Disable a SQL Server Network Protocol
##################################################################
function ChangeSQLProtocolStatus($server,$instance,$protocol,$enable){

	$smo = 'Microsoft.SqlServer.Management.Smo.'

	$wmi = new-object ($smo + 'Wmi.ManagedComputer')

	$singleWmi = $wmi | where {$_.Name -eq $server}

	$uri = "ManagedComputer[@Name='$server']/ServerInstance[@Name='$instance']/ServerProtocol[@Name='$protocol']"

	$protocol = $singleWmi.GetSmoObject($uri)

	$protocol.IsEnabled = $enable

	$protocol.Alter()

	$protocol
}

##################################################################
# Enable TCP/IP SQL Server Network Protocol
##################################################################
ChangeSQLProtocolStatus -server "BTS2010LAB01" -instance "MSSQLSERVER" -protocol "TCP" -enable $true

##################################################################
# Enable Named Pipes SQL Server Network Protocol
##################################################################
ChangeSQLProtocolStatus -server "BTS2010LAB01" -instance "MSSQLSERVER" -protocol "NP" -enable $true

##################################################################
# Disable Shared Memory SQL Server Network Protocol
##################################################################
ChangeSQLProtocolStatus -server "BTS2010LAB01" -instance "MSSQLSERVER" -protocol "SM" -enable $false

##################################################################
# Disable VIA SQL Server Network Protocol
##################################################################
ChangeSQLProtocolStatus -server "BTS2010LAB01" -instance "MSSQLSERVER" -protocol "VIA" -enable $false

Because after we correctly set up the protocols, we need to restart the SQL services for the changes to take effect, this script additional also restart all the services and also BizTalk Services if they exist! However this last part is optional.

$service = get-service "MSSQLSERVER"
restart-service $service.name -force #Restart SQL Services

$service = get-service "ENTSSO" #Start Enterprise Single Sign-On Service
if( $service -ne $null )
{
	start-service $service.name
}
get-service BTS* | foreach-object -process {start-service $_.Name} # Start BizTalk Services

Once again I also like to thank my friend Rui Machado for always want and help in all my small challenges, In this particular sample Rui was the creator of the function ChangeSQLProtocolStatus ;)

The script can be found and download on Microsoft TechNet Gallery:
How to set SQL Server Network Protocols in the SQL Server for BTS Databases (7.4 KB)
Microsoft TechNet Gallery

About these ads
Comments
  1. Hi Sandro,
    another great article, thanks!
    What about different SQL services? Do we have to stop the SQL Server FullText Search?

    • Hi Leonid, Thanks.
      When we force the restart of the MSSQLSERVER he will also restart all SQL services that depend on it and stop all the other dependent services like BizTalk Services and Enterprise Single Sign-On Service

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s