<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Microsoft SQL Server Tips &amp; Tricks</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/sqlserverfaq/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/sqlserverfaq/feed.xml</link>
    <description>Tips and Tricks for the SQL Server Enthusiast</description>
    <lastBuildDate>Sun, 22 Jan 2017 03:17:31 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Automate SQL server backup file removal/deletion from Azure blob storage</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlserverfaq/automate-sql-server-backup-file-removaldeletion-from-azure-blob-storage</link>
      <pubDate>Sun, 22 Jan 2017 03:17:31 GMT</pubDate>
      <dc:creator><![CDATA[Pradeep Adiga]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlserverfaq/?p=4555</guid>
      <description><![CDATA[In this post, we would like to explain one of the interesting issues that we encountered while...]]></description>
      <content:encoded><![CDATA[<p style="text-align: justify">In this post, we would like to explain one of the interesting issues that we encountered while working with azure backups and restore.</p>

<h3 style="text-align: justify">Symptoms</h3>
<p style="text-align: justify">Cannot delete the .bak files from azure blob storage through maintenance plans or any other options from SQL which have been backed up using backup to URL or managed backup</p>

<h3 style="text-align: justify">Cause</h3>
<p style="text-align: justify">At this time we don’t have any functionality available to automate the deletion of the backup files on Azure blob Storage account/container.</p>

<h3 style="text-align: justify">Resolution</h3>
<p style="text-align: justify">You can backup and restore using maintenance plans to azure blob storage but you cannot use the maintenance cleanup task to clear the data from blob storage like you can do for your on premise.
The only way out to achieve this is by using PowerShell script. We developed the below script which will delete the files which have been modified earlier than one day in the below script from the date it’s called. The date can be changed 1 day to any number needed per requirements. In the below example, we have deleted the files which are older than one day.
We created a new storage account for testing this by using</p>
<p style="text-align: justify"><code>#To create new storage account
New-AzureRmStorageAccount -ResourceGroupName resource-Test1 -Name bkuptourl -Type Standard_LRS -Location NorthEurope
#Script to delete backup files
$bacs = Get-ChildItem $location # use "-Filter *.bak" or "-Filter *.trn" for deleting bak or trn files specifically
$container="bkup"
$StorageAccountName="bkuptourl"
$StorageAccountKey="xsVyDSvy48113b37ZEu0/VNkYAz9R81cO7UwOTp4qhDYU9zNbLAjioiOh3FVnzhO8n3tDYOyWnSkn=="
$context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$filelist = Get-AzureStorageBlob -Container $container -Context $context
foreach ($file in $filelist | Where-Object {$_.LastModified.DateTime -lt ((Get-Date).AddDays(-1))})
{
$removefile = $file.Name
if ($removefile -ne $null)
{
Write-Host "Removing file $removefile"
Remove-AzureStorageBlob -Blob $removeFile -Container $container -Context $context
}
}
</code></p>

<h3 style="text-align: justify">Sample output</h3>
<p style="text-align: justify"><a href="https://msdnshared.blob.core.windows.net/media/2017/01/SamplePSOutput.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/01/SamplePSOutput.png" alt="samplepsoutput" width="864" height="330" class="alignnone size-full wp-image-4565" /></a></p>
&nbsp;

<strong>Written by</strong>:
<span style="color: #0000ff">Ujjwal Patel</span>, Support Engineer, SQL Server Support

<strong>Reviewed by</strong>:
<span style="color: #0000ff">Raghavendra Srinivasan</span>, Sr. Support Engineer, SQL Server Support]]></content:encoded>
    </item>
    <item>
      <title>Automated backups configuration fails when configured from Azure portal</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlserverfaq/automated-backups-configuration-fails-when-configured-from-azure-portal</link>
      <pubDate>Sun, 22 Jan 2017 02:58:59 GMT</pubDate>
      <dc:creator><![CDATA[Pradeep Adiga]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlserverfaq/?p=4515</guid>
      <description><![CDATA[In this post, we would like to explain one of the interesting issues that we encountered while using...]]></description>
      <content:encoded><![CDATA[<p style="text-align: justify">In this post, we would like to explain one of the interesting issues that we encountered while using the automated backup feature for a VM from the azure portal (We can find the option once we click on VM &gt; SQL Server Configuration&gt; Automated Backup)</p>

<h3 style="text-align: justify">Symptoms</h3>
<p style="text-align: justify">Cannot Configure Automated backups in azure VM from the portal which was created on ARM (Azure Resource Manager Model). It fails with the following error</p>
<code>• TYPE
Microsoft.Compute/virtualMachines/extensions
• RESOURCE ID
/subscriptions/6c28b945-6d98-403d-8936-5e658f228a0f/resourceGroups/Group/providers/Microsoft.Compute/virtualMachines/LTO-CT-SQL/extensions/SqlIaasExtension
• STATUSMESSAGE
{ "status": "Failed", "error": { "code": "ResourceDeploymentFailure", "message": "The resource operation completed with terminal provisioning state 'Failed'.", "details": [ { "code": "VMExtensionHandlerNonTransientError", "message": "Handler 'Microsoft.SqlServer.Management.SqlIaaSAgent' has reported failure for VM Extension 'SqlIaasExtension' with terminal error code '1009' and error message: 'Enable failed for plugin (name: Microsoft.SqlServer.Management.SqlIaaSAgent, version 1.2.10.0) with exception Command C:\\Packages\\Plugins\\Microsoft.SqlServer.Management.SqlIaaSAgent\\1.2.10.0\\enable.cmd of Microsoft.SqlServer.Management.SqlIaaSAgent has exited with Exit code: 255'" } ] } }
• RESOURCE
LTO-CT-SQL/SqlIaasExtension
• OPERATION ID
B3B967D4EF42741A
</code>
<h3 style="text-align: justify">Cause</h3>
<p style="text-align: justify">SQL IAAS Agent Service was disabled and dint starts due to insufficient permissions.</p>

<h3 style="text-align: justify">Resolution</h3>
<p style="text-align: justify">We can reproduce the issue by the following method.</p>
<p style="text-align: justify">We deployed a VM on our end and navigated to VM &gt; SQL Server Configuration&gt; Automated Backup and this failed with a similar error:</p>
<p style="text-align: justify"><a href="https://msdnshared.blob.core.windows.net/media/2017/01/AutomatedBackup.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/01/AutomatedBackup.png" alt="automatedbackup" width="960" height="634" class="alignnone size-full wp-image-4525" /></a></p>
<p style="text-align: justify"><code>Error", "message": "Handler <strong>'Microsoft.SqlServer.Management.SqlIaaSAgent' has reported failure</strong> for VM Extension 'SqlIaasExtension' with terminal error code '1009' and error message: 'Enable failed for plugin (name: Microsoft.SqlServer.Management.SqlIaaSAgent, version 1.2.10.0) with exception
statusMessage:{"status":"Failed","error":{"code":"ResourceDeploymentFailure","message":"The resource operation completed with terminal provisioning state 'Failed'.","details":[{"code":"VMExtensionHandlerNonTransientError","message":"Handler 'Microsoft.SqlServer.Management.SqlIaaSAgent' has <strong>reported failure for VM Extension 'SqlIaasExtension' with terminal error code '1009' and error message: 'Enable failed for plugin (name: Microsoft.SqlServer.Management.SqlIaaSAgent, version 1.2.10.0) with exception Command C:\\Packages\\Plugins\\Microsoft.SqlServer.Management.SqlIaaSAgent\\1.2.10.0\\enable.cmd</strong> of Microsoft.SqlServer.Management.SqlIaaSAgent has exited with Exit code: -532462766'"}]}}</code></p>
<p style="text-align: justify">We then went to the VM and checked the event viewer application and system logs and found the below errors:</p>
<p style="text-align: justify"><code>The Microsoft SQL Server IaaS Agent service failed to start due to the following error:
The service did not start due to a logon failure.</code></p>
<strong>The SQLIaaSExtension service was unable to log on as NT Service\SQLIaaSExtension with the currently configured password due to the following error:
Logon failure: the user has not been granted the requested logon type at this computer</strong>.

Service: SQLIaaSExtension
Domain and account: NT Service\SQLIaaSExtension

<strong>This service account does not have the required user right "Log on as a service."</strong>

The above clearly indicates that SQLIAASEXTENSION account needs to have the permissions in security policy.

We went to Run&gt; Secpol.msc&gt; Under Security settings looked for Local Policies &gt; User Rights Assignment &gt; Log on as a service (In right pane) &gt;Right click and go to its properties and this account with Admin permissions.

<a href="https://msdnshared.blob.core.windows.net/media/2017/01/SecPol.msc_.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/01/SecPol.msc_.png" alt="secpol-msc" width="624" height="232" class="alignnone size-full wp-image-4535" /></a>

We then again tried to create automated backup and dint see the error in event viewer.
Now to figure out where is this account used, we looked at services.msc and found the account is used by <strong>Microsoft SQL IAAS Agent service</strong>.
We saw the service is in a stopped state.

<a href="https://msdnshared.blob.core.windows.net/media/2017/01/services.msc_.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/01/services.msc_.png" alt="services-msc" width="624" height="67" class="alignnone size-full wp-image-4545" /></a>
<p style="text-align: justify">Now researching on this, we found SQL Server IAAS Agent service can help us to automate some administrative tasks, for example run jobs, monitors SQL Server, and processes alerts. <strong>When we enable Automated Backup on virtual machine, the extension will be automatically installed but somehow it didn’t start in our scenario due to the account permission issues</strong>.</p>
<p style="text-align: justify">We started the service and then tried to configure the automated backups from the azure portal and saw it completed successfully without any errors. In case if it still fails even after that then the next step is to Look at the locations <strong>C:\WindowsAzure\Logs</strong> and C:\Packages\Plugins for any errors in the IAAS VM.</p>

<h3 style="text-align: justify">More Information:</h3>
<p style="text-align: justify">We require the Microsoft SQL IAAS Agent service in running state for enabling automated backups and its functioning. When we enable Automated Backup on our virtual machine, the extension will be automatically installed.
Automated Backup automatically configures Managed Backup to Microsoft Azure for all existing and new databases on an Azure VM running SQL Server 2014 Standard or Enterprise. This enables us to configure regular database backups that utilize durable Azure blob storage. Automated Backup depends on the <a target="_blank" href="https://azure.microsoft.com/en-in/documentation/articles/virtual-machines-windows-sql-server-agent-extension/">SQL Server IaaS Agent Extension</a>.</p>

<h3 style="text-align: justify">Related articles:</h3>
<p style="text-align: justify">More information on Automated Backups: <a target="_blank" href="https://azure.microsoft.com/en-in/documentation/articles/virtual-machines-windows-sql-automated-backup/">https://azure.microsoft.com/en-in/documentation/articles/virtual-machines-windows-sql-automated-backup/</a></p>
<p style="text-align: justify">More information on IAAS Agent Service: <a href="https://azure.microsoft.com/en-in/documentation/articles/virtual-machines-windows-sql-server-agent-extension/">https://azure.microsoft.com/en-in/documentation/articles/virtual-machines-windows-sql-server-agent-extension/</a></p>
&nbsp;

<strong>Written by</strong>:
<span style="color: #0000ff">Ujjwal Patel</span>, Support Engineer, SQL Server Support

<strong>Reviewed by</strong>:
<span style="color: #0000ff">Raghavendra Srinivasan</span>, Sr. Support Engineer, SQL Server Support

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Error: Could not deploy package. Unable to connect to target server.</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlserverfaq/error-could-not-deploy-package-unable-to-connect-to-target-server</link>
      <pubDate>Wed, 12 Oct 2016 07:23:30 GMT</pubDate>
      <dc:creator><![CDATA[Balmukund]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlserverfaq/?p=4495</guid>
      <description><![CDATA[In this post we would like to explain one of the interesting issue that we encountered while...]]></description>
      <content:encoded><![CDATA[<p>In this post we would like to explain one of the interesting issue that we encountered while deploying a DACPAC from sqlpackage.exe. <h2>Symptoms</h2> <p>Cannot Deploy DACPAC Extracted from SQL 2012 Server from .NET custom code or from SQLPackage.exe command to SQL 2014 <p><a href="https://msdnshared.blob.core.windows.net/media/2016/10/image392.png"><img title="image" style="border-top: 0px;border-right: 0px;border-bottom: 0px;padding-top: 0px;padding-left: 0px;border-left: 0px;padding-right: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/10/image_thumb361.png" width="1024" height="144"></a> <p><font face="Courier New">C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin&gt;SqlPackage.exe /Action:Publish /SourceFile:"C:\temp\AgentLink2_11.0.6020.dacpac" /tsn:"RAGHAVSDC" /TargetDatabaseName:TestACM</font> <p><font face="Courier New">Publishing to database 'TestACM' on server 'RAGHAVSDC'.<br>The dac history table will not be updated.<br>Initializing deployment (Start)<br>Initializing deployment (Failed)<br><font color="#ff0000">*** Could not deploy package.<br>Unable to connect to target server.</font></font> <h2>Cause </h2> <p>We don’t have a DAC Folder at location <u>C:\Program Files (x86)\Microsoft SQL Server\120\</u> in the system but have the folder<u> C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin</u> (We can successfully publish to SQL 2012 but not SQL 2014)</p> <h2>Resolution</h2> <p>To reproduce the issue, please find a DAC folder at location <u>C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin</u> </p> <p>Open a CMD with administrator privileges and navigate to this path and run the sqlpackage.exe to publish it to a SQL 2014/2016 server and we will get the same exact error  <p><font color="#ff0000">“*** Could not deploy package.</font> <p><font color="#ff0000">Unable to connect to target server.”</font> <p>The above looks like to be a connectivity error at our first glance but this is not the case here. We tested the connectivity for this on multiple machines and didn’t find an issue with it. The solution to the problem is we need to install the DAC Framework <a href="https://www.microsoft.com/en-in/download/details.aspx?id=42293">https://www.microsoft.com/en-in/download/details.aspx?id=42293 </a>and once installed, we will be able to see the DAC Folder at <u>C:\Program Files (x86)\Microsoft SQL Server\120\DAC\</u></p> <p>We then can try to publish the DACPAC from sqlpackage.exe from the 120 Location and it gets published successfully.</p> <h4><a href="https://msdnshared.blob.core.windows.net/media/2016/10/image393.png"><img title="image" style="border-top: 0px;border-right: 0px;border-bottom: 0px;padding-top: 0px;padding-left: 0px;border-left: 0px;padding-right: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/10/image_thumb362.png" width="1117" height="259"></a></h4> <h4><b><u>More Information:</u></b> </h4> <p>In the above scenario, we noticed that we can only publish the DACPAC for the version the DACPAC file was created for.</p> <p>If we have taken a DACPAC for SQL 2012, then we can publish is to any higher version of SQL but it needs to be published from the 120 folder (<u>C:\Program Files (x86)\Microsoft SQL Server\120\DAC\Bin</u>) if we want to publish to SQL 2014. If we are trying to publish the DACPAC taken from SQL 2012 to 2016 then we need to publish the package from the 130 Folder (<u>C:\Program Files (x86)\Microsoft SQL Server\130\DAC\Bin</u>)</p> <p>DACPAC is a feature of our Data Tier application which will allow us to backup the schema of our database. In simple terms, it is only database schema (definition without the data) which can be used on higher versions of SQL Server. SQLPackage.exe is a utility which allows us to automate database development and projects in our environment.</p> <h4><b><u>Related articles:</u></b></h4> <p>SQLPackage.exe: <a href="https://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx">https://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx</a> <p>Data Tier Applications: <a href="https://msdn.microsoft.com/en-us/library/ee210546.aspx">https://msdn.microsoft.com/en-us/library/ee210546.aspx</a> <p>Design and Implementation for DACPAC: <a href="https://technet.microsoft.com/en-us/library/ee210546(v=sql.110).aspx">https://technet.microsoft.com/en-us/library/ee210546(v=sql.110).aspx</a> <p>DAC Framework download: <a href="https://www.microsoft.com/en-in/download/details.aspx?id=42293">https://www.microsoft.com/en-in/download/details.aspx?id=42293 </a>   <p><strong>Written by – Ujjwal Patel, Support Engineer.<br>Reviewed by – Raghavendra, , Sr. Support Engineer.</strong></p>]]></content:encoded>
    </item>
    <item>
      <title>Troubleshooting SSL on SQL Server Issue - AT_KEYEXCHANGE is not set</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlserverfaq/troubleshooting-ssl-on-sql-server-issue-at_keyexchange-is-not-set</link>
      <pubDate>Tue, 04 Oct 2016 03:31:35 GMT</pubDate>
      <dc:creator><![CDATA[Pradeep Adiga]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlserverfaq/?p=4395</guid>
      <description><![CDATA[It is one of the pre-requisites for the KEY-SPEC value of the SSL self-signed certificate to be set...]]></description>
      <content:encoded><![CDATA[It is one of the pre-requisites for the KEY-SPEC value of the SSL self-signed certificate to be set to 1, for it to be loaded to the SQL server. Due to the glitches during the creation of the certificate there may be scenarios arising where in this value might not be set to 1. If this happens to be 0 or 2, then the <strong>AT_KEYEXCHANGE </strong>parameter of the certificate is not said to be set. Once when I was working with one of my partner we encountered the exact issue of <strong>AT_KEYEXCHANGE not set</strong> or the <strong>KEY-SPEC value</strong> of the SSL certificate used at their end <strong>is not set to 1.</strong> I also found that, this is often a question that has been asked a lot of times in the various forums and discussions. On trying to find if there were any resolutions, couldn’t find any blogs on the internet to help us resolve this issue.

As a result of which I researched on the same and came up with a couple of action plans by reproducing the issue at my end by intentionally creating certificate violating the <strong>KEY_SPEC</strong> parameter value and blogged the resulted observations which will help us resolve the issue and thus instead of creating a new certificate, the existing certificate can be re-used.

<strong><u>Scenario</u></strong><strong><u>: </u></strong>

I will be creating a SSL self-signed certificate with the <strong>KEY_SPEC not set to 1</strong> and explain how to correct it and make the certificate eligible to load it to SQL server.

<strong><u>Approaches:</u></strong>
<ol>
 	<li><strong> </strong><strong><u>By creating a ‘PSEUDO’ REGISTRY KEY</u></strong></li>
</ol>
<ul>
 	<li>Firstly, I have created a faulty SSL certificate with the KEY_SPEC not set to 1.</li>
</ul>
<ul>
 	<li>If in case any assistance is needed to create the certificate refer to my previous blog wherein I have explained the different ways of creating the SSL certificate.</li>
</ul>
<ul>
 	<li>On creating the certificate, running the <strong>checkSQLssl</strong> tool on the server gives the following validation report for the certificate created.</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2016/10/110.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/10/110.png" alt="1" width="546" height="219" class="size-full wp-image-4405 aligncenter" /></a>
<ul>
 	<li>Now to address this issue, <strong>create a DWORD</strong> value called <strong>“NoProviderName”</strong> and <strong>set it to 1</strong> at the path <strong>HKCU\Software\Microsoft\Windows\CurrentVersion\PFX.</strong></li>
</ul>
<ul>
 	<li>Export the certificate in the <strong>.PFX format</strong> and deleted it from the store through the MMC.</li>
</ul>
<ul>
 	<li>To export, Right click on the certificate -&gt; All Tasks -&gt; Export and the Certificate Export Wizard appears, click on <strong>NEXT</strong> to continue.</li>
</ul>
<ul>
 	<li>Note that for the certificate to be exported from the MMC, initially during its creation itself, the private key should be made exportable. If not the <strong>Yes, export the private key</strong> radio button as shown will be greyed out and that will be the last nail in the coffin.</li>
</ul>
<ul>
 	<li>In the Export Private Key page click on the <strong>Yes, export the private key</strong> radio button as shown and click on <strong>NEXT</strong> to continue.</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2016/10/210.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/10/210.png" alt="2" width="481" height="263" class="size-full wp-image-4415 aligncenter" /></a>
<ul>
 	<li>In the Export File Format page, make sure radio button for <strong>.PFX format</strong> is checked as shown and click on <strong>NEXT</strong> to continue.</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2016/10/33.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/10/33.png" alt="3" width="550" height="390" class="size-full wp-image-4425 aligncenter" /></a>
<ul>
 	<li>In the Security page, <strong>check the Password check box</strong>, enter a <strong>password</strong> and confirm it which will be needed during the re-importing of the certificate. Click on <strong>NEXT</strong> to continue.</li>
</ul>
<ul>
 	<li>In the File to Export page <strong>browse to the physical location</strong> where you need the certificate to be exported on the machine. Click on <strong>NEXT</strong> and follow it by clicking on <strong>FINISH</strong> to complete the export process.</li>
</ul>
<ul>
 	<li>Now navigate to the location where you have exported the certificate and then run the below command from elevated <strong>CMD</strong> prompt:</li>
</ul>
<strong>      Certutil -importpfx &lt;PFXFILENAME.pfx&gt; AT_KEYEXCHANGE</strong>

where PFXFILENAME is the file name of the exported certificate.

<a href="https://msdnshared.blob.core.windows.net/media/2016/10/42.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/10/42.png" alt="4" width="541" height="85" class="size-full wp-image-4435 aligncenter" /></a>

Now the issue of the certificate will be resolved and can be verified by running the checkSQLssl tool again and the certificate will be eligible now to be loaded to SQL server.

<a href="https://msdnshared.blob.core.windows.net/media/2016/10/52.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/10/52.png" alt="5" width="539" height="171" class="size-full wp-image-4445 aligncenter" /></a><strong><u></u></strong>

<strong><u>2. Without creating any REGISTRY KEY:</u></strong>

&nbsp;

Say for instance, due to security or the product functionality concerns if the ‘PSEUDO’ registry key creation is not permissible, then this approach can be used where in the course of action remains almost the same as the previous one except for the fact that there is no requirement of any registry key to be created.
<ul>
 	<li>Even here the procedure remains almost the same.</li>
</ul>
<ul>
 	<li>We have to <strong>export the certificate</strong> and then we have to <strong>re-import</strong> it but there is no need of a registry key creation in this case.</li>
</ul>
<ul>
 	<li>Re-import the certificate using the following command:</li>
</ul>
<strong>certutil -csp "Microsoft Strong Cryptographic Provider" - importpfx &lt;PFXFILENAME.pfx&gt;</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2016/10/62.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/10/62.png" alt="6" width="599" height="73" class="size-full wp-image-4455 aligncenter" /></a>
<ul>
 	<li>Thus the issue with the certificate will now be resolved and thus it will be now eligible to be loaded to SQL server.</li>
</ul>
<h5></h5>
<h5><strong>Written by</strong>:
<span style="color: #0000ff">Shreyas R</span>, Support Engineer, SQL Server Support</h5>
<h5><strong>Reviewed by</strong>:
<span style="color: #0000ff">Sravani Saluru</span>, Support Escalation Engineer, SQL Server Support
<span style="color: #0000ff">Pradeep M M</span>, Escalation Engineer, SQL Server Support</h5>]]></content:encoded>
    </item>
    <item>
      <title>Creating and Registering SSL Certificates</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlserverfaq/creating-and-registering-ssl-certificates</link>
      <pubDate>Mon, 26 Sep 2016 03:07:19 GMT</pubDate>
      <dc:creator><![CDATA[Pradeep Adiga]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlserverfaq/?p=4186</guid>
      <description><![CDATA[A few days back, I was working with one of our partners who had a requirement of creating a SSL...]]></description>
      <content:encoded><![CDATA[A few days back, I was working with one of our partners who had a requirement of creating a SSL self-signed certificate through MMC console. As we are already aware that it is a complex and a tedious procedure, tried developing a script to ease the task for us. Also found that there were a lot of partners asking for assistance in having a script based approach to create the certificates.
Tried finding a way out by looking through various discussion forums which yielded nothing, but queries to build a script to accomplish the task. Addressing this requirement of the partner pool, here is the blog explaining the script based way of creating the Self-signed certificates and registering them meeting the pre-requisites of SQL server.
By developing the script based way of creating the certs, it is just at the run of a command we will get the SSL self-signed certificates created and ready to be registered. Along with the creation of the certificate, this blog also explains the different ways of registering those certificates.

&nbsp;

<span style="text-decoration: underline"><strong>Scenario 1</strong></span>:

I will be creating a SSL self-signed certificate using the following 3 methods:
<ul>
 	<li>Using Makecert util from the SDK.</li>
 	<li>Using certreq command and a script.sine</li>
 	<li>Using powershell command.</li>
</ul>
<strong><u>Steps to be followed:</u></strong>
<ol>
 	<li><strong> </strong><strong><u>Using Makecert util:</u></strong></li>
</ol>
<ul>
 	<li>Firstly, the pre-requisite for using this method is to have <strong>Windows SDK</strong> installed on the machine.</li>
 	<li>Navigate to the location where you have the <strong>makecert</strong> util and then Run the below command from elevated <strong>CMD</strong> prompt:</li>
 	<li>Run the following command to create the certificate:</li>
</ul>
<code>makecert -r -pe -n "CN=MININT-Q99PLQN.fareast.corp.microsoft.com" -b 10/16/2015 -e 12/01/2020 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky
exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12
</code>
<a href="https://msdnshared.blob.core.windows.net/media/2016/09/137.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/09/137.png" alt="1" width="1045" height="98" class="alignnone size-full wp-image-4295" /></a>
<ul>
 	<li>We will have the certificate created under the MMC console --&gt; Certificate snap in --&gt; Local Computer --&gt; Personal section</li>
 	<li>As per the parameters specified, the certificate will be created with the following set of specifications:
<ul>
 	<li>The common name of the certificate will be “MININT-Q99PLQN.fareast.corp.microsoft.com” which is the FQDN of the machine.</li>
 	<li>The private key will be enabled for exporting.</li>
 	<li>Certificate will be created in the Computer account -&gt; Personal -&gt; Certificate store</li>
 	<li>Validity period will be 10-16-2015 to 12-01-2020</li>
 	<li>The server authentication will be enabled. [eku = 1.3.6.1.5.5.7.3.1]</li>
 	<li>Key Spec value will be set to 1. [AT_KEYEXCHANGE will be enabled]</li>
 	<li>The algorithm used here for encryption is Microsoft RSA SChannel Cryptographic Provider.</li>
</ul>
</li>
</ul>
<strong>2.<span class="Apple-tab-span"> </span>Using Certreq command:</strong>
<ul>
 	<li>Firstly, we need to save the below script in a text document with a .inf extension.</li>
</ul>
<code>[Version]
Signature = "$Windows NT$"
[NewRequest]
Subject = "CN = MININT-Q99PLQN.fareast.corp.microsoft.com"
FriendlyName = test1.contoso.com
MachineKeySet = true
RequestType=Cert
;SignatureAlgorithm = SHA256
KeyLength = 4096
KeySpec = 1
KeyUsage = 0xA0
MachineKeySet = True
Exportable = TRUE
Hashalgorithm = sha512
ValidityPeriod = Years
ValidityPeriodUnits = 10
[EnhancedKeyUsageExtension]
OID=1.3.6.1.5.5.7.3.1
</code>
<ul>
 	<li>Navigate to the location where you have saved this request.inf file and then Run the below command from elevated CMD prompt</li>
</ul>
<code>Certreq -new -f .inf .cer</code>
<ul>
 	<li>We will have the certificate created under the MMC console --&gt; Certificate snap in --&gt; LocalComputer --&gt; Personal section</li>
 	<li>The advantages of this technique is that it <strong>does not require</strong> the Windows SDK installed and the key length can be subjected to changes where as if it is using <strong>makecert</strong> it would be by <strong>default</strong> <strong>set to '2048' for 'RSA' and '512' for 'DSS'</strong></li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2016/09/228.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/09/228.png" alt="2" width="773" height="239" class="alignnone size-full wp-image-4315" /></a>

<span style="text-decoration: underline"><strong>3.<span class="Apple-tab-span"> </span>Using Power-shell command</strong></span>
<ul>
 	<li>Here is the approach to create the SSL certificate satisfying the pre-requisites to load it for SQL server using the power-shell command.</li>
 	<li>Run Powershell as an administrator and enter the following command (where DnsName = Host name or FQDN of the machine)</li>
</ul>
<code>New-SelfSignedCertificate -DnsName MININT-Q99PLQN.fareast.corp.microsoft.com -CertStoreLocation cert:\LocalMachine\My -FriendlyName test99 -KeySpec KeyExchange</code>
<a href="https://msdnshared.blob.core.windows.net/media/2016/09/3111.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/09/3111.png" alt="31" width="1792" height="278" class="alignnone size-full wp-image-4325" /></a>

<strong><u>Scenario: 2</u></strong>

I will be registering the SSL self-signed certificate using the following 2 methods:
<ul>
 	<li>Through the SQL Server Configuration Manager</li>
 	<li>Through explicit registration</li>
</ul>
<strong><u>Steps to be followed:</u></strong>
<ol>
 	<li><strong> </strong><strong><u>Through SQL Server Configuration Manager:</u></strong></li>
</ol>
<ul>
 	<li>Initially need to check the health of the certificate using the CheckSQLssl.exe tool.</li>
 	<li>Here are the pre-requisites for the SSL certificate to use it for SQL server:
<ul>
 	<li>Certificate must be present in the <strong>Local computer certificate store</strong> or the <strong>current user certificate store</strong>.</li>
 	<li>Certificate age must be present within the <strong>validity period</strong>.</li>
 	<li>Certificate must be meant for <strong>server authentication</strong>. (EKU should specify Server Authentication [1.3.6.1.5.5.7.3.1])</li>
 	<li>Certificate must be created using the <strong>KEY_SPEC option of AT_KEYEXCHANGE (KEY_SPEC=1)</strong></li>
 	<li>Common name of the certificate should be the <strong>host name or the FQDN of the server computer</strong>.</li>
 	<li>Running the tool using the command prompt will generate the following report</li>
</ul>
</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2016/09/418.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/09/418.png" alt="4" width="610" height="230" class="alignnone size-full wp-image-4335" /></a>
<ul>
 	<li>On getting all the validation checks ‘OK’ regarding the pre-requisites of the certificate we can go ahead register it.</li>
 	<li>On SSCM, expand SQL server network configuration -&gt; Right click on ‘Protocols for &lt;Instance name&gt; -&gt; Properties. Turn the ‘<strong>Forced Encryption</strong>’ <strong>to Yes</strong>.</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2016/09/514.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/09/514.png" alt="5" width="539" height="195" class="alignnone size-full wp-image-4345" /></a>
<ul>
 	<li>Click on the <strong>‘Certificate’ tab</strong> where the certificates will be listed and select the required certificate from the list and <strong>restart the service</strong>.</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2016/09/612.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/09/612.png" alt="6" width="462" height="290" class="alignnone size-full wp-image-4365" /></a>
<ul>
 	<li>Thus the SSL certificate will be loaded to the selected SQL server and this can be verified by analyzing the <strong>SQL error logs</strong> for the below message and verifying it with the thumbprint of the certificate in MMC.</li>
</ul>
<code>The certificate <strong>[Cert Hash(sha1) "BFB714872C7B2CD761ADEB1893BFC99581D3420B"]</strong> was successfully loaded for encryption.</code>
<ul>
 	<li>To verify the thumbprint, in MMC double click on the certificate which is loaded, click on <strong>‘Details’ tab</strong> and click on <strong>thumbprint</strong> in the list.</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2016/09/77.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/09/77.png" alt="7" width="512" height="446" class="alignnone size-full wp-image-4385" /></a>

<span style="text-decoration: underline"><strong>2.<span class="Apple-tab-span"> </span>Through explicit registration:</strong></span>
<ul>
 	<li>Even after the validation checks are proved to be OK by the <strong>CheckSQLssl</strong> tool and still if the certificate is not listed in SSCM, then follow this technique.</li>
 	<li>Run ‘regedit’ and open <strong>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQLServer\SuperSocketNetLib</strong> and enter the <strong>thumbprint</strong> of the certificate without spaces to the ‘Certificate’ value.</li>
 	<li>Note that in case of a <strong>clustered environment</strong> in those nodes whose <strong>FQDN does not match</strong> with the certificate name, the certificate will not be listed in the configuration manager. In that case <strong>explicit registration</strong> is the only way to register the certificate.</li>
 	<li>Then on restarting the SQL service the SSL certificate will be loaded to SQL and this can be verified again by analyzing the <strong>SQL server error logs</strong>.</li>
</ul>
&nbsp;

&nbsp;
<h5><strong>Written by</strong>:
<span style="color: #0000ff">Shreyas R</span>, Support Engineer, SQL Server Support</h5>
<h5><strong>Reviewed by</strong>:
<span style="color: #0000ff">Sravani Saluru</span>, Support Escalation Engineer, SQL Server Support
<span style="color: #0000ff">Pradeep M M</span>, Escalation Engineer, SQL Server Support</h5>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server Service fails to start after applying patch. Error: CREATE SCHEMA failed due to previous errors.</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlserverfaq/sql-server-service-fails-to-start-after-applying-patch-error-create-schema-failed-due-to-previous-errors</link>
      <pubDate>Thu, 14 Jul 2016 06:04:46 GMT</pubDate>
      <dc:creator><![CDATA[Balmukund]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlserverfaq/?p=4165</guid>
      <description><![CDATA[In this post we would like to explain one of the interesting issues that we encountered while...]]></description>
      <content:encoded><![CDATA[<p>In this post we would like to explain one of the interesting issues that we encountered while upgrading a SQL Server Instance.</p> <h2>Symptoms</h2> <p>SQL Server Service fails to start after applying SQL patch due to misconfiguration in MSDB.  <p><b><u>Error:-</u></b>  <p><font face="Courier New"><font size="2"><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; </i></font></font><font face="Courier New"><font size="2"><i>Script level upgrade for database 'master' failed because upgrade step </i><b><i><u>'msdb110_upgrade.sql'</u></i></b><i> encountered error 2714, state 6, severity 25.</i></font></font> <font face="Courier New"><font size="2"><i>Severity: 16, State: 0.</i><i></i></font></font> <br><font face="Courier New"><font size="2"><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; <strong><font color="#ff0000">CREATE SCHEMA failed due to previous errors</font>.</strong></i><i></i></font></font><strong> <br></strong><font face="Courier New"><font size="2"><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; Error: 912, Severity: 21, State: 2.</i><i></i></font></font> <br><font face="Courier New"><font size="2"><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; Script level upgrade for database 'master' failed because upgrade step 'msdb110_upgrade.sql' encountered error 2714, state 6, severity 25. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting. Examine the previous error log entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion.</i><i></i></font></font> </p> <p><font face="Courier New"><font size="2"><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; Error: 3417, Severity: 21, State: 3.</i><i></i></font></font> <br><font face="Courier New"><font size="2"><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup, repair it, or rebuild it. For more information about how to rebuild the master database, see SQL Server Books Online.</i><i></i></font></font>  <p><i><font size="2" face="Courier New">2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; SQL Server shutdown has been initiated</font></i>·  <h2>Cause </h2> <ul> <li>The upgrade script [<b><i><u>msdb110_upgrade.sql</u></i></b><b><i><u>]</u></i></b> executes during the first restart of SQL after the service pack installation.  <li>This script hits an exception during recreation of database role called “<b><u>DatabaseMailUserRole</u></b>”.  <li>This is due to the fact that the schema named “<b><u>DatabaseMailUserRole</u></b>” was owned by other database role then “<b><u>DatabaseMailUserRole</u></b>” – DBO role in our case. </li></ul> <h2>Resolution </h2> <p>1. Start the SQL server service using Trace flag -T902 ( 902 : Used to skip execution of any scripts during SQL Startup)  <blockquote> <p><a href="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image0024.jpg"><img title="clip_image002" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;padding-top: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px" border="0" alt="clip_image002" src="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image002_thumb2.jpg" width="700" height="166"></a> </p></blockquote> <p>Or follow these steps:  <blockquote> <p><font size="2">· Open SQL Server Configuration Manager. </font> <p><font size="2">· In SQL Server Configuration Manager, click <b>SQL Server Services</b>. </font> <p><font size="2">· Double-click the SQL Server service. </font> <p><font size="2">· In the <b>SQL Server Properties </b>dialog box, click the <b>Advanced </b>tab. </font> <p><font size="2">· On click the <b>Advanced </b>tab, locate the <b>Startup Parameters </b>item. </font> <p><font size="2">· Add ;-T902 to the end of the existing string value, and then click <b>OK</b>. </font> <p><font size="2">· Restart the SQL server service</font> </p></blockquote> <p>2. Connect to the SQL instance and backup the MSDB database </p> <p>3. Manually delete the schema named “<b><u>DatabaseMailUserRole</u></b>”  <p><b></b> <p>Management studio &gt; Expand <b>MSDB</b> Database &gt; Go to <b>Security</b> &gt; <b>Schemas</b> &gt; Look for <b>DatabaseMailuserRole</b>  <p><a href="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image0044.jpg"><img title="clip_image004" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;padding-top: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px" border="0" alt="clip_image004" src="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image004_thumb4.jpg" width="421" height="499"></a>  <p>4. Now delete the schema named <b><u>DatabaseMailuserRole</u></b>.  <p>5. Restart the SQL Server service.  <p><a href="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image0064.jpg"><img title="clip_image006" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;padding-top: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px" border="0" alt="clip_image006" src="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image006_thumb4.jpg" width="712" height="225"></a>  <h2>More information </h2> <ul> <li>Starting SQL Server 2008 onwards, whenever we upgrade or apply a patch on SQL, it upgrades only the binaries and not the database and its objects.  <li>Once the upgrade completes and the service restarts for the first time, it starts the database upgrade using script <b>msdb110_upgrade.sql </b>which is located under </li></ul> <blockquote> <p><font size="2">C:\Program Files\Microsoft SQL Server\MSSQLXX.YYYY\MSSQL\Install\ </font> <p><font size="2">XX : SQL Version&nbsp; <br></font><font size="2">SQL 2008/R2&nbsp; &gt;10 <br></font><font size="2">SQL 2012&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt;11 <br></font><font size="2">SQL 2014&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt; 12 </font></p></blockquote> <p><b></b> <p><b></b> <p><em><font face="Courier New">-------------------------------------------------------------- <br>-- Database Mail roles and permissions <br>-------------------------------------------------------------- <br>-- Create the DatabaseMailUserRole role <br>IF (EXISTS (SELECT * <br>FROM msdb.dbo.sysusers <br>WHERE (name = N'DatabaseMailUserRole') <br>AND (issqlrole = 1))) <br>BEGIN -- there are no members in the role, then drop and re-create it <br>IF ((SELECT COUNT(*) <br>FROM msdb.dbo.sysusers&nbsp;&nbsp; su, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msdb.dbo.sysmembers sm <br>WHERE (su.uid = sm.groupuid) <br>AND (su.name = N'DatabaseMailUserRole') <br>AND (su.issqlrole = 1)) = 0) <br>BEGIN <br>EXECUTE msdb.dbo.sp_droprole @rolename = N'DatabaseMailUserRole'&nbsp;&nbsp; <br>EXECUTE msdb.dbo.sp_addrole @rolename = N'DatabaseMailUserRole'&nbsp; <strong>&lt;&lt; **************Point of failure</strong> <br>END <br>END <br>ELSE <br>EXECUTE msdb.dbo.sp_addrole @rolename = N'DatabaseMailUserRole' <br></font></em></p> <ul> <li>The command “SP_ADDROLE” fails as it also creates schema named “<b>DatabaseMailUserRole</b>” which already exists in the MSDB database.  <li>The previous command “SP_DROPROLE” was unable to delete the schema “<b>DatabaseMailUserRole</b>” as it was owned by other database role– DBO role in our case. </li></ul> <p><b><u>Steps to repro the error:-</u></b>  <p>1. Change the schema owner of “<b><u>DatabaseMailUserRole</u></b>” to DBO  <p><em><font face="Courier New">USE [msdb] <br>GO <br>ALTER AUTHORIZATION ON SCHEMA::[DatabaseMailUserRole] TO [dbo] <br>GO </font></em> <p>2. Try to execute the below statement&nbsp; and we hit the same error:  <p><i><font face="Courier New">EXECUTE msdb.dbo.sp_droprole @rolename = N'DatabaseMailUserRole'&nbsp;&nbsp; <br></font></i><i><font face="Courier New">EXECUTE msdb.dbo.sp_addrole @rolename = N'DatabaseMailUserRole'&nbsp; <strong>&lt;&lt;&lt;**************Point of failure</strong></font></i><strong> </strong> <p><b><i></i></b> <p><b><i><a href="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image0085.jpg"><img title="clip_image008" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;padding-top: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px" border="0" alt="clip_image008" src="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image008_thumb5.jpg" width="648" height="203"></a></i></b>  <p><b><i></i></b> <p><b><u>Related articles:</u></b>  <ul> <li>Using the SQL Server Service Startup Options <a href="https://msdn.microsoft.com/en-us/library/ms190737(v=sql.105).aspx">https://msdn.microsoft.com/en-us/library/ms190737(v=sql.105).aspx</a>  <li>How to: Configure Server Startup Options (SQL Server Configuration Manager) <a href="https://msdn.microsoft.com/en-us/library/ms345416(v=sql.105).aspx">https://msdn.microsoft.com/en-us/library/ms345416(v=sql.105).aspx</a>  <li>ALTER AUTHORIZATION (Transact-SQL) <a href="https://msdn.microsoft.com/en-us/library/ms187359.aspx">https://msdn.microsoft.com/en-us/library/ms187359.aspx</a>  <li>sp_addrole (Transact-SQL) <a href="https://msdn.microsoft.com/en-us/library/ms189743.aspx">https://msdn.microsoft.com/en-us/library/ms189743.aspx</a></li></ul> <h6><font style="font-weight: bold"><br>Written by</font>:<br>Ujjwal Patel, Support Engineer, SQL Server Support</h6> <h6><font style="font-weight: bold">Reviewed by:<br></font>Raghavendra Srinivasan, Support Engineer, SQL Server Support</h6>]]></content:encoded>
    </item>
    <item>
      <title>Setting up Service Broker where the initiator database is part of the AG</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlserverfaq/setting-up-service-broker-where-the-initiator-database-is-part-of-the-ag</link>
      <pubDate>Wed, 29 Jul 2015 03:17:08 GMT</pubDate>
      <dc:creator><![CDATA[Pradeep Adiga]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlserverfaq/2015/07/29/setting-up-service-broker-where-the-initiator-database-is-part-of-the-ag/</guid>
      <description><![CDATA[&#160;  There have been several posts on setting up Service Broker where the database is part of the...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>There have been several posts on setting up Service Broker where the database is part of the Availability Group. This is a one stop blog for setting up Service Broker where the initiator database is part of the AG</p>  <p>What happens when the AG fails over? Should there be any additional steps in setting up the service broker so that it resumes its operation after an AG failover? This blog post answers all these questions with details wherever required. The below technet article outlines the steps: <a title="https://msdn.microsoft.com/en-IN/library/hh710058.aspx" href="https://msdn.microsoft.com/en-IN/library/hh710058.aspx">https://msdn.microsoft.com/en-IN/library/hh710058.aspx</a></p>  <p>In this blog, we will discuss about the steps along with the screenshots, wherever applicable. </p>  <h5>Requirements:</h5>  <p><strong></strong></p>  <ol>   <li>Service Broker has to be setup and enabled on the database before the database is added to the AG. </li>    <li>Availability Group must possess a listener. </li>    <li>Service Broker endpoints must be configured on every instance of SQL Server that hosts an availability replica for the availability group. </li> </ol>  <h5>Environment:</h5>  <p><u>AlwaysOn      <br /></u>&#160;&#160;&#160; Name of Availability Group: AGService     <br />&#160;&#160;&#160; AG Listener: LIST     <br />&#160;&#160;&#160; VM1\INS1 : Primary Synchronous Replica     <br />&#160;&#160;&#160; VM2\INS2 : Secondary Synchronous Replica (Automatic Failover) </p>  <p><u>Service Broker</u>     <br />&#160;&#160;&#160; VM1\INS1 : Initiator 1     <br />&#160;&#160;&#160; VM2\INS2 : Initiator 2     <br />&#160;&#160;&#160; VM3\INS3 : Target</p>  <p>At the end of this blog, we’ll be setting up the below environment</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/4722.image_6F6D0516.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/4722.image_5F00_6F6D0516.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/0083.image_thumb_2FB0FF69.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/0083.image_5F00_thumb_5F00_2FB0FF69.png" width="487" height="212" /></a> </p>  <h5>Overview:</h5>  <p>‹•›&#160;&#160; Setup service broker on the initiator: VM1\INS1 and target: VM3\INS3    <br />‹•›&#160;&#160; Take a backup of the Initiator database on VM1\INS1 and restore it with NORECOVERY on the 2nd Initiator (secondary replica) –VM2\INS2     <br />‹•›&#160;&#160; Create Service Broker endpoint on the secondary replica: VM2\INS2     <br />‹•›&#160;&#160; Create Route on the secondary replica: VM2\INS2     <br />‹•›&#160;&#160; Backup the Service Master Key from the primary replica and restore it on the secondary replica.     <br />‹•›&#160;&#160; Add the 2 initiator databases (from VM1\INS1 and VM2\INS2) to the AG</p>  <h5>Steps:</h5>  <ol>   <li>Setup service broker on the initiator: VM1\INS1 and target: VM3\INS3      <br />Here, we’ll be setting up Service Broker as we normally do, with initiator as VM1\INS1 and VM2\INS2 as target.       <br />The T-SQL here to do the same is included, just so there is more clarity on the naming convention that is used in this blog. These scripts have been taken from the below MSDN article:       <br /><a href="https://technet.microsoft.com/en-us/library/bb839483(v=sql.105).aspx">https://technet.microsoft.com/en-us/library/bb839483(v=sql.105).aspx</a> </li> </ol>  <blockquote>   <p><font size="1" face="Courier New">------------------------------------------       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Lesson 1: Creating the Target Database--        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --***[connect to the TARGET instance- VM3\INS3]***--        <br />------------------------------------------ </font></p> </blockquote>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create a Service Broker endpoint     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE master;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; IF EXISTS (SELECT * FROM master.sys.endpoints WHERE name = N'InstTargetEndpoint')      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DROP ENDPOINT InstTargetEndpoint;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE ENDPOINT InstTargetEndpoint     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; STATE = STARTED      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; AS TCP ( LISTENER_PORT = 4022, LISTENER_IP=ALL )      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; FOR SERVICE_BROKER (AUTHENTICATION = WINDOWS );      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create the target database, master key, and user     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE master;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; IF EXISTS (SELECT * FROM sys.databases WHERE name = N'TargetDB')      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DROP DATABASE TargetDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE DATABASE TargetDB;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE TargetDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE MASTER KEY      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ENCRYPTION BY PASSWORD = N'&lt;EnterStrongPassword1Here&gt;';      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE USER TargetUser WITHOUT LOGIN;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create the target certificate &amp; backup the certificate </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE CERTIFICATE InstTargetCertificate      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AUTHORIZATION TargetUser      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; WITH SUBJECT = 'Target Certificate',      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EXPIRY_DATE = N'12/31/3010'; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; BACKUP CERTIFICATE InstTargetCertificate     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TO FILE = N'\\DC\Certshare\InstTargetCertificate_INS3.cer';      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create message type for request and reply     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE TargetDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Create message type [//RequestMsg]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; go      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Create message type [//ReplyMsg]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; go </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create a contract for the above created message     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE TargetDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Create contract [//SampleContract]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; (      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [//RequestMsg] sent by initiator,      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [//ReplyMsg] sent by target      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ) </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create Queue &amp; Service for target      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE TargetDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE QUEUE TargetQueue_TargetDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; go      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE SERVICE [//TargetService]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; AUTHORIZATION TargetUser      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ON QUEUE TargetQueue_TargetDB([//SampleContract]);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO</font></p>  <p>Below queries need to be run on the initiator. At this point, we’ll run it only on VM1\INS1 which will be the primary replica on the AG.</p>  <p>&#160;&#160;&#160;&#160;&#160; <font size="1" face="Courier New">---------------------------------------------     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Lesson 2: Creating the Initiator Database--      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --***[connect to the INITIATOR instance: VM1\INS1]***--      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; -------------------------------------------- </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create a Service Broker endpoint     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE master;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; IF EXISTS (SELECT * FROM sys.endpoints      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; WHERE name = N'InstInitiatorEndpoint')      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DROP ENDPOINT InstInitiatorEndpoint;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE ENDPOINT InstInitiatorEndpoint      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; STATE = STARTED      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; AS TCP ( LISTENER_PORT = 4022, LISTENER_IP=ALL )      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; FOR SERVICE_BROKER (AUTHENTICATION = WINDOWS );      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create the initiator database, master key, and user     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE master;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; IF EXISTS (SELECT * FROM sys.databases      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; WHERE name = N'InitiatorDB')      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DROP DATABASE InitiatorDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE DATABASE InitiatorDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE InitiatorDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE MASTER KEY     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ENCRYPTION BY PASSWORD = N'&lt;EnterStrongPassword2Here&gt;';      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE USER InitiatorUser WITHOUT LOGIN;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create the initiator certificate </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE CERTIFICATE InstInitiatorCertificate     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AUTHORIZATION InitiatorUser      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; WITH SUBJECT = N'Initiator Certificate',      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EXPIRY_DATE = N'12/31/3010'; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; BACKUP CERTIFICATE InstInitiatorCertificate     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TO FILE =       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; N'\\dc\certshare\InstInitiatorCertificate_INS1.cer';      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create message type for request and reply     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE InitiatorDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Create message type [//RequestMsg]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; go      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Create message type [//ReplyMsg]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; go </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create a contract for the above created message     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE InitiatorDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Create contract [//SampleContract]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; (      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [//RequestMsg] sent by initiator,      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [//ReplyMsg] sent by target      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ) </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create the initiator queue and service </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE QUEUE InitiatorQueue_InitiatorDB; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE SERVICE [//InitiatorService]     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AUTHORIZATION InitiatorUser      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ON QUEUE InitiatorQueue_InitiatorDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create references to target objects     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE USER TargetUser WITHOUT LOGIN; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE CERTIFICATE InstTargetCertificate      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AUTHORIZATION TargetUser      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; FROM FILE =       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; N'\\DC\certshare\InstTargetCertificate_INS3.cer'      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create routes </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; DECLARE @Cmd NVARCHAR(4000); </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; SET @Cmd = N'USE InitiatorDB;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE ROUTE Initiator_TO_Target_Route      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; WITH SERVICE_NAME =N''//TargetService'',      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ADDRESS = N''TCP://VM3:4022'';'; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; EXEC (@Cmd); </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; SET @Cmd = N'USE msdb     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE ROUTE Inst_Local_InitiatorRoute      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; WITH SERVICE_NAME =      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; N''//InitiatorService'',      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ADDRESS = N''LOCAL'''; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; EXEC (@Cmd);     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE REMOTE SERVICE BINDING TargetBinding      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TO SERVICE      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; N'//TargetService'      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; WITH USER = TargetUser; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO</font>&#160; </p>  <p>Now, on the target: VM3\INS3, run the below. Note that I am using the routing address of VM1 while creating a Target_To_Initiator Route. We’ll change that to name of the AG listener after we test if the service broker is sending and receiving messages between the VM1\INS1 and VM3\INS3( Without AG in picture)</p>  <p>&#160;&#160;&#160;&#160;&#160;&#160; <font size="1" face="Courier New">-------------------------------------------------------     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Lesson 3: Completing the Target Conversation Objects      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --***[connect to the TARGET instance VM3\INS3]***--      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ------------------------------------------------------- </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create references to initiator objects     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE TargetDB      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE USER InitiatorUser WITHOUT LOGIN; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE CERTIFICATE InstInitiatorCertificate     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AUTHORIZATION InitiatorUser      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; FROM FILE = N'\\DC\certshare\InstInitiatorCertificate_INS1.cer';      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Create routes </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; DECLARE @Cmd NVARCHAR(4000); </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; SET @Cmd = N'USE TargetDB;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE ROUTE Target_To_Initiator_Route      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; WITH SERVICE_NAME =      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; N''//InitiatorService'',      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ADDRESS = N''TCP://VM1:4022'';'; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; EXEC (@Cmd); </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; SET @Cmd = N'USE msdb     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE ROUTE Inst_Local_TargetRoute      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; WITH SERVICE_NAME =      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; N''//TargetService'',      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ADDRESS = N''LOCAL'''; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; EXEC (@Cmd);     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GRANT SEND      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ON SERVICE::[//TargetService]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TO InitiatorUser;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE REMOTE SERVICE BINDING InitiatorBinding      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TO SERVICE N'//InitiatorService'      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; WITH USER = InitiatorUser;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO</font></p>  <p>&#160;</p>  <p>This is the basic Service Broker setup between VM1\INS1 and VM3\INS3. You can check by sending and receiving messages using the below scripts.</p>  <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font size="1" face="Courier New">--------------------------------------------------     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Lesson 4: Beginning the Conversation--      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --***[connect to the INITIATOR instance VM1\INS1]***--      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; -------------------------------------------------- </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE InitiatorDB;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; DECLARE @InitDlgHandle UNIQUEIDENTIFIER;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; DECLARE @RequestMsg NVARCHAR(100);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; BEGIN TRANSACTION;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; BEGIN DIALOG @InitDlgHandle      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; FROM SERVICE [//InitiatorService]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; TO SERVICE N'//TargetService'      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ON CONTRACT [//SampleContract]WITH ENCRYPTION = Off;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; SELECT @RequestMsg = N'&lt;RequestMsg:1&gt;Message for Target service.&lt;/RequestMsg:1&gt;';      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; SEND ON CONVERSATION @InitDlgHandle      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; MESSAGE TYPE [//RequestMsg]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; (@RequestMsg);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; SELECT @RequestMsg AS SentRequestMsg; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; COMMIT TRANSACTION;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO</font></p>  <p>Once the message is sent from the initiator, it can be seen by querying the Target Queue on the target database.</p>  <p><font size="1" face="Courier New">Select *from [dbo].[TargetQueue_TargetDB]</font></p>  <p>If it is not present on the Target queue, query the sys.transmission_queue on the initiator. If there are any errors, it will be shown on the transmission_status column.   <br />Now, run the below on the target instance to receive the request and send a reply.</p>  <p>&#160;</p>  <p>&#160;&#160;&#160;&#160;&#160;&#160; <font size="1" face="Courier New">--------------------------------------------------     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Lesson 5: Receiving a Request and Sending a Reply--      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --***[connect to the TARGET instance VM3\INS3]***--      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; -------------------------------------------------- </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Receive the request and send a reply     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE TargetDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; DECLARE @RecvReqDlgHandle UNIQUEIDENTIFIER;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; DECLARE @RecvReqMsg NVARCHAR(100);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; DECLARE @RecvReqMsgName sysname; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; BEGIN TRANSACTION; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; WAITFOR     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ( RECEIVE TOP(1)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @RecvReqDlgHandle = conversation_handle,      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @RecvReqMsg = message_body,      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @RecvReqMsgName = message_type_name      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; FROM [dbo].[TargetQueue_TargetDB]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ), TIMEOUT 1000; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; SELECT @RecvReqMsg AS ReceivedRequestMsg; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; IF @RecvReqMsgName = N'//RequestMsg'     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; BEGIN      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DECLARE @ReplyMsg NVARCHAR(100);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SELECT @ReplyMsg =      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; N'&lt;ReplyMsg:1&gt;Message for Initiator service.&lt;/ReplyMsg:1&gt;'; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SEND ON CONVERSATION @RecvReqDlgHandle     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MESSAGE TYPE [//ReplyMsg]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (@ReplyMsg); </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; END CONVERSATION @RecvReqDlgHandle;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; END </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; SELECT @ReplyMsg AS SentReplyMsg; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; COMMIT TRANSACTION;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO</font></p>  <p>&#160;</p>  <p>Make sure this message appears in the initiator queue on VM1\INS1</p>  <p>End the conversation by running the below on the initiator: VM1\INS1:</p>  <p>&#160;</p>  <p>&#160;&#160;&#160;&#160;&#160;&#160; <font size="1" face="Courier New">--------------------------------------------------     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Lesson 6: Receiving the Reply and Ending the Conversation--      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --***[connect to the INITIATOR instance VM1\INS1]***--      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; -------------------------------------------------- </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; --Receive the reply and end the conversation     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; USE InitiatorDB;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; DECLARE @RecvReplyMsg NVARCHAR(100);     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; DECLARE @RecvReplyDlgHandle UNIQUEIDENTIFIER; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; BEGIN TRANSACTION; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; WAITFOR     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ( RECEIVE TOP(1)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @RecvReplyDlgHandle = conversation_handle,      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @RecvReplyMsg = message_body      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; FROM [dbo].[InitiatorQueue_InitiatorDB]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ), TIMEOUT 1000; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; END CONVERSATION @RecvReplyDlgHandle; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; -- Display recieved request.     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; SELECT @RecvReplyMsg AS ReceivedReplyMsg; </font></p>  <p><font size="1" face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; COMMIT TRANSACTION;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO</font></p>  <p>&#160;</p>  <p>2.&#160; Take a Full database backup and transaction log backup of the Initiator database on VM1\INS1 and restore them with NORECOVERY on the 2nd Initiator (secondary replica) –VM2\INS2.&#160; </p>  <p>3.&#160; Create an availability group named AGService and add the database: InitiatorDB on VM1\INS1 and VM2\INS2 to it with VM1\INS1 as the primary replica and VM2\INS2 as the Synchronous secondary replica. Also, create an AG listener named: LIST.</p>  <p>4.&#160; Now, failover the AG to VM2\INS2 Replica. After the failover, check if Service Broker is enabled on the database we restored on VM2\INS2. The is_broker_enabled bit should be set to 1.</p>  <p>select is_broker_enabled, *from sys.databases where name=’InitiatorDB’</p>  <p>5.&#160; Create the Service Broker endpoint on the replica: VM2\INS2</p>  <p><font size="1" face="Courier New">USE MASTER     <br />GO      <br />CREATE ENDPOINT InstInitiatorEndpoint      <br />STATE = STARTED      <br />AS TCP ( LISTENER_PORT = 4022, LISTENER_IP=ALL )      <br />FOR SERVICE_BROKER (AUTHENTICATION = WINDOWS );      <br />GO </font></p>  <p>&#160;</p>  <p>6.&#160; Create the local Route on the MSDB of the secondary replica: VM2\INS2</p>  <p>&#160;&#160;&#160; <font size="1" face="Courier New">&#160;&#160;&#160; USE msdb     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; GO      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; CREATE ROUTE Inst_Local_InitiatorRoute      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; WITH SERVICE_NAME =      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; N'//InitiatorService',      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ADDRESS = N'LOCAL'</font></p>  <p>7.&#160; Backup the Service Master Key from the primary replica VM1\INS1 and restore it on the secondary replica VM2\INS2</p>  <p><font size="1" face="Courier New">BACKUP SERVICE MASTER KEY TO FILE='\\DC\CertShare\SMKVM1' encryption by password='IamStrong!' </font></p>  <p><font size="1" face="Courier New">RESTORE SERVICE MASTER KEY FROM FILE='\\DC\CertShare\SMKVM1' decryption by password=' IamStrong!' FORCE</font></p>  <p><font size="1" face="Courier New">--Run this on VM3\INS3     <br />USE [TARGETDB]      <br />GO      <br />ALTER ROUTE [Target_To_Initiator_Route]      <br />WITH SERVICE_NAME =      <br />&#160;&#160;&#160;&#160;&#160;&#160; N’//InitiatorService’,      <br />&#160;&#160;&#160;&#160; ADDRESS = N’TCP://LIST:4022’</font></p>  <p><font size="1" face="Courier New"></font></p>  <p>8.&#160; Now, we’ll change the Target_To_Initiator_Route to use the AG Listener. This will make sure Service Broker works even after an AG failover.</p>  <p><font size="1" face="Courier New">--Run this on VM3\INS3     <br />USE [TARGETDB]      <br />GO      <br />ALTER ROUTE [Target_To_Initiator_Route]      <br />WITH SERVICE_NAME =      <br />&#160;&#160;&#160;&#160;&#160;&#160; N’//InitiatorService’,      <br />&#160;&#160;&#160;&#160; ADDRESS = N’TCP://LIST:4022’</font></p>  <p>You can test the service broker functionality now between the new initiator: VM2\INS2 and target: VM3\INS3 by running the queries in step 1 (only from Lesson 4 to Lesson 6).</p>  <p><strong><u>Author</u>: </strong></p>  <p><strong><font color="#0000ff">Prabhjot Kaur</font>, Support Engineer, Microsoft India GTSC </strong></p>  <p><strong><u>Reviewed by</u>: </strong></p>  <p><strong><font color="#0000ff">Balmukund Lakhani</font>, Support Escalation Engineer, Microsoft India GTSC</strong></p>]]></content:encoded>
    </item>
    <item>
      <title>Error configuring distribution- "Publishing and distribution are supported only in SQL Server version 7.0 or later"</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlserverfaq/error-configuring-distribution-publishing-and-distribution-are-supported-only-in-sql-server-version-7-0-or-later</link>
      <pubDate>Tue, 28 Jul 2015 00:17:00 GMT</pubDate>
      <dc:creator><![CDATA[Pradeep Adiga]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlserverfaq/2015/07/28/error-configuring-distribution-publishing-and-distribution-are-supported-only-in-sql-server-version-7-0-or-later/</guid>
      <description><![CDATA[&nbsp;
I recently installed an instance of SQL Server 2016 on one of my server. Later when I tried...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p>I recently installed an instance of SQL Server 2016 on one of my server. Later when I tried to configure the new instance as Distributor I faced the below error:</p>
<h4>Error:</h4>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/8662.clip_image002_12EBDF54.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/8662.clip_5F00_image002_5F00_12EBDF54.jpg"><img style="display: inline; border: 0px;" title="clip_image002" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/1680.clip_image002_thumb_1DABC75A.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/1680.clip_5F00_image002_5F00_thumb_5F00_1DABC75A.jpg" alt="clip_image002" width="717" height="162" border="0" /></a></p>
<p>------------------------------ <br />TITLE: Configure Distribution Wizard <br />------------------------------ <br />'Prod\SQL16' cannot be configured for publishing and distribution. Publishing and distribution are supported only in SQL Server version 7.0 or later. <br />For help, click: <a href="https://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&amp;ProdVer=12.0.2000.8&amp;EvtSrc=Microsoft.SqlServer.Management.UI.ConfigureWizardErrorSR&amp;EvtID=ServerTooOld&amp;LinkId=20476">https://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&amp;ProdVer=12.0.2000.8&amp;EvtSrc=Microsoft.SqlServer.Management.UI.ConfigureWizardErrorSR&amp;EvtID=ServerTooOld&amp;LinkId=20476</a> <br />------------------------------ <br />BUTTONS: <br />OK <br />------------------------------</p>
<p>&nbsp;</p>
<h4>Observations:</h4>
<ul>
<li>From the Object Explorer I can clearly see that I&rsquo;m connected to the latest version of SQL[SQL 2016] but still I&rsquo;m getting the above error.</li>
</ul>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/3288.clip_image0026_286BAF60.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/3288.clip_5F00_image0026_5F00_286BAF60.jpg"><img style="display: inline; border: 0px;" title="clip_image002[6]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/4705.clip_image0026_thumb_481D19D9.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/4705.clip_5F00_image0026_5F00_thumb_5F00_481D19D9.jpg" alt="clip_image002[6]" width="420" height="209" border="0" /></a></p>
<ul>
<li>Verified that I&rsquo;m not connected to Web/SQL Express edition which supports Subscriber only. More info at <a href="https://msdn.microsoft.com/en-us/library/cc645993.aspx">Features Supported by the Editions of SQL Server 2016</a></li>
</ul>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/3000.clip_image0028_575382A6.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/3000.clip_5F00_image0028_5F00_575382A6.jpg"><img style="display: inline; border: 0px;" title="clip_image002[8]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/4213.clip_image0028_thumb_56E9E062.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/4213.clip_5F00_image0028_5F00_thumb_5F00_56E9E062.jpg" alt="clip_image002[8]" width="524" height="199" border="0" /></a></p>
<p>&nbsp;</p>
<ul>
<li>Tried to configure Distributor using the <a href="https://msdn.microsoft.com/en-us/library/ms151192.aspx#TsqlProcedure">TSQL script</a> and it successfully executed. After this when I tried to create a new publication I again got the same error. So the issue seems to be only with the GUI.</li>
</ul>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/3326.clip_image00210_48ADF823.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/3326.clip_5F00_image00210_5F00_48ADF823.jpg"><img style="display: inline; border: 0px;" title="clip_image002[10]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/3465.clip_image00210_thumb_25808D71.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/3465.clip_5F00_image00210_5F00_thumb_5F00_25808D71.jpg" alt="clip_image002[10]" width="749" height="295" border="0" /></a></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/7633.clip_image00212_2BC9F4B0.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/7633.clip_5F00_image00212_5F00_2BC9F4B0.jpg"><img style="display: inline; border: 0px;" title="clip_image002[12]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/2112.clip_image00212_thumb_22048D38.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/2112.clip_5F00_image00212_5F00_thumb_5F00_22048D38.jpg" alt="clip_image002[12]" width="446" height="103" border="0" /></a></p>
<ul>
<li>I then verified the version of SQL Server management studio which I was using and noticed that it was an older version- SQL 2014 SSMS.</li>
</ul>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/5635.clip_image00214_33E3B1B6.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/5635.clip_5F00_image00214_5F00_33E3B1B6.jpg"><img style="display: inline; border: 0px;" title="clip_image002[14]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/4111.clip_image00214_thumb_3A2D18F5.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/4111.clip_5F00_image00214_5F00_thumb_5F00_3A2D18F5.jpg" alt="clip_image002[14]" width="346" height="288" border="0" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h4>Solution:</h4>
<ul>
<li>I then launched SSMS for SQL Server 2016 and I was able to configure the instance as distributor. As mentioned before we can also use the TSQL commands to configure.</li>
</ul>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/1411.clip_image00216_12F56071.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/1411.clip_5F00_image00216_5F00_12F56071.jpg"><img style="display: inline; border: 0px;" title="clip_image002[16]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/0602.clip_image00216_thumb_76E73236.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/0602.clip_5F00_image00216_5F00_thumb_5F00_76E73236.jpg" alt="clip_image002[16]" width="388" height="310" border="0" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/8664.clip_image001_2CEBB144.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/8664.clip_5F00_image001_5F00_2CEBB144.jpg"><img style="display: inline; border: 0px;" title="clip_image001" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/8688.clip_image001_thumb_6CB8287A.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/8688.clip_5F00_image001_5F00_thumb_5F00_6CB8287A.jpg" alt="clip_image001" width="315" height="286" border="0" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/5344.clip_image0015_498ABDC8.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/5344.clip_5F00_image0015_5F00_498ABDC8.jpg"><img style="display: inline; border: 0px;" title="clip_image001[5]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/3225.clip_image0015_thumb_693C2841.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/3225.clip_5F00_image0015_5F00_thumb_5F00_693C2841.jpg" alt="clip_image001[5]" width="321" height="271" border="0" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ul>
<li>I faced this issue as I had multiple version of SQL server management studio on the same server</li>
</ul>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/1057.clip_image00218_2D12ED4A.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/1057.clip_5F00_image00218_5F00_2D12ED4A.jpg"><img style="display: inline; border: 0px;" title="clip_image002[18]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/4150.clip_image00218_thumb_7E4FC558.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/4150.clip_5F00_image00218_5F00_thumb_5F00_7E4FC558.jpg" alt="clip_image002[18]" width="302" height="292" border="0" /></a></p>
<h4>Related Articles:</h4>
<p>&middot; Configure Distribution <a href="https://msdn.microsoft.com/en-us/library/ms151860.aspx">https://msdn.microsoft.com/en-us/library/ms151860.aspx</a></p>
<p>&middot; How to: Configure Publishing and Distribution (Replication Transact-SQL Programming) <a href="https://technet.microsoft.com/en-us/library/ms147363(v=sql.105).aspx">https://technet.microsoft.com/en-us/library/ms147363(v=sql.105).aspx</a></p>
<p>&middot; How to: Configure Publishing and Distribution (SQL Server Management Studio) <a href="https://technet.microsoft.com/en-us/library/ms151192(v=sql.105).aspx">https://technet.microsoft.com/en-us/library/ms151192(v=sql.105).aspx</a></p>
<p>&middot; sp_adddistributor (Transact-SQL) <a href="https://technet.microsoft.com/en-us/library/ms176028(v=sql.105).aspx">https://technet.microsoft.com/en-us/library/ms176028(v=sql.105).aspx</a></p>
<p>&middot; sp_adddistributiondb (Transact-SQL) <a href="https://technet.microsoft.com/en-us/library/ms189755(v=sql.105).aspx">https://technet.microsoft.com/en-us/library/ms189755(v=sql.105).aspx</a></p>
<p>&nbsp;</p>
<p><strong>Author:</strong></p>
<p><strong><span style="color: #0000ff;">Raghavendra Srinivasan</span> , Support Engineer, Microsoft India GTSC</strong></p>
<p><strong>Reviewed by:</strong></p>
<p><strong><span style="color: #0000ff;">Balmukund Lakhani</span>, Support Escalation Engineer, Microsoft India GTSC</strong></p>]]></content:encoded>
    </item>
    <item>
      <title>How to find which user deleted the user database in SQL Server</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlserverfaq/how-to-find-which-user-deleted-the-user-database-in-sql-server</link>
      <pubDate>Sun, 17 May 2015 04:41:00 GMT</pubDate>
      <dc:creator><![CDATA[Pradeep Adiga]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlserverfaq/2015/05/17/how-to-find-which-user-deleted-the-user-database-in-sql-server/</guid>
      <description><![CDATA[&nbsp;
In one of the recent scenarios we noticed that a user database was deleted and customer...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p>In one of the recent scenarios we noticed that a user database was deleted and customer wanted to which user has dropped the database. We know that multiple user had full access on that database. <br />In this post I&rsquo;ll be sharing the steps to find the details of user who drop the database.</p>
<h3>Method-1</h3>
<ul>
<li><strong>Connect the SQL Server instance using management studio</strong></li>
<li><strong>Right-click on the instance and select </strong></li>
</ul>
<blockquote>
<p><strong>&ldquo;Reports&rdquo;&mdash;&ldquo;Standard Reports&rdquo;&mdash;&ldquo;Schema Changes History&rdquo;</strong></p>
</blockquote>
<ul>
<li><strong>We get a report of schema changes for all databases from which we can get the user account which was used to delete/drop the database</strong></li>
</ul>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/6646.clip_image0024_0C190862.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/6646.clip_5F00_image0024_5F00_0C190862.jpg"><img style="display: inline; border: 0px;" title="clip_image002[4]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/7103.clip_image0024_thumb_71DB2FEE.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/7103.clip_5F00_image0024_5F00_thumb_5F00_71DB2FEE.jpg" alt="clip_image002[4]" width="879" height="431" border="0" /></a></p>
<h3>Sample output:</h3>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/2781.clip_image0026_183FA3EB.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/2781.clip_5F00_image0026_5F00_183FA3EB.jpg"><img style="display: inline; border: 0px;" title="clip_image002[6]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/4705.clip_image0026_thumb_49CDA231.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/4705.clip_5F00_image0026_5F00_thumb_5F00_49CDA231.jpg" alt="clip_image002[6]" width="882" height="470" border="0" /></a></p>
<p><strong><em>Note: This report doesn&rsquo;t contain the details of application or the server from which the DROP statement was executed.</em></strong></p>
<h3>Method &ndash; 2:</h3>
<ul>
<li>Get the location of SQL Errorlog using one of the below commands</li>
</ul>
<blockquote>
<p><span style="color: #0000ff;"><strong><em>sp_readerrorlog</em></strong><strong><em> 0,1,'Logging SQL Server messages in file'</em></strong></span></p>
<p><strong><em><span style="color: #0000ff;">go</span></em></strong></p>
<p><strong><span style="text-decoration: underline;"><span style="color: #0000ff;">Sample output:</span></span></strong></p>
<p><span style="color: #0000ff;">LogDate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ProcessInfo&nbsp; Text</span></p>
<p><span style="color: #0000ff;">----------------------- ------------ ---------------------------------------------------------------------------------------------------------------</span></p>
<p><span style="color: #0000ff;">2015-01-09 15:31:31.330 Server&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Logging SQL Server messages in file 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL14\MSSQL\Log\ERRORLOG'.</span></p>
<p><span style="color: #0000ff;"><strong><em>--or</em></strong><strong><em></em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>select</em></strong><strong><em> SERVERPROPERTY('errorlogfilename')</em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>go</em></strong><strong><em></em></strong></span></p>
<p><strong><span style="text-decoration: underline;"><span style="color: #0000ff;">Sample output:</span></span></strong></p>
<p><span style="color: #0000ff;">-----------------------------------------------------------------------------------------------------------</span></p>
<p><span style="color: #0000ff;">C:\Program Files\Microsoft SQL Server\MSSQL12.SQL14\MSSQL\Log\ERRORLOG</span></p>
</blockquote>
<ul>
<li>Look for default SQL trace files and open the trace files which points to the time of issue. &ldquo;<strong>Log_</strong><strong>111.trc</strong>&rdquo; for example.<strong> </strong></li>
</ul>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/3187.clip_image0028_0FE0EFF6.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/3187.clip_5F00_image0028_5F00_0FE0EFF6.jpg"><img style="display: inline; border: 0px;" title="clip_image002[8]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/0486.clip_image0028_thumb_5EE13F48.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/0486.clip_5F00_image0028_5F00_thumb_5F00_5EE13F48.jpg" alt="clip_image002[8]" width="579" height="222" border="0" /></a></p>
<ul>
<li>Make a copy of the file in same or different location &ldquo;<strong>log_111 - Copy.trc</strong>&rdquo;</li>
<li>We can now manually open this file in SQL Profiler and search for keywork &ldquo;<strong>Object:Deleted</strong>&rdquo; or load it to SQL table and use T-SQL query to get the details. Here I&rsquo;m providing the steps for T-SQL</li>
</ul>
<blockquote>
<p><span style="color: #0000ff;"><strong><em>--To load the trace to SQL table</em></strong><strong><em></em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>use</em></strong><strong><em> tempdb</em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>go</em></strong><strong><em></em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>SELECT</em></strong><strong><em> * INTO trace_table FROM ::fn_trace_gettable('C:\Program Files\Microsoft SQL Server\MSSQL12.SQL14\MSSQL\Log\log_111 - Copy.trc', default)</em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>go</em></strong><strong><em></em></strong></span></p>
<p><strong><em><span style="color: #0000ff;">--Get the details of the deleted database</span></em></strong></p>
<p><span style="color: #0000ff;"><strong><em>--Change the value of the </em></strong><strong><em>database name</em></strong><strong><em> to the one which was deleted</em></strong><strong><em></em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>select</em></strong><strong><em> DatabaseID,DatabaseName,LoginName,HostName,ApplicationName,StartTime from tempdb.dbo.trace_table </em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>where</em></strong><strong><em> DatabaseName = 'somedb' and eventclass =47 -- 47 is Object:Deleted Event Class</em></strong></span></p>
<p>&nbsp;</p>
<p><strong><span style="text-decoration: underline;"><span style="color: #0000ff;">Sample output:</span></span></strong></p>
<p><span style="color: #0000ff;">DatabaseID&nbsp; DatabaseName LoginName&nbsp; HostName&nbsp;&nbsp;&nbsp;&nbsp; ApplicationName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StartTime</span></p>
<p><span style="color: #0000ff;">----------- ------------ ---------- ------------ -----------------------------------------------------------------------</span></p>
<p><span style="color: #0000ff;">26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>SomeDB</strong> <strong>SQL_User1</strong> <strong>Client1</strong> <strong>Microsoft SQL Server Management Studio - Query</strong> <strong>2015-01-14 12:43:46.630</strong></span></p>
<p><span style="color: #0000ff;">26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SomeDB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>SQL_User1</strong> <strong>Client1</strong>&nbsp;&nbsp;&nbsp; Microsoft SQL Server Management Studio - Query&nbsp; 2015-01-14 12:43:46.630</span></p>
<p><span style="color: #0000ff;">(2 row(s) affected)</span></p>
</blockquote>
<p>From the above we can clearly say that&nbsp; &ldquo;<strong>SQL_User1</strong>&rdquo; user deleted the database from machine &ldquo;<strong>Client1</strong>&rdquo; using SSMS at the above mentioned time.</p>
<p>&nbsp;</p>
<h3>Method &ndash; 3</h3>
<p>Use the below script to get the details of deleted/dropped databases. We can explicitly specify the name of the database which was deleted or get the output for all databases.</p>
<p><span style="color: #0000ff;"><strong><em>use</em></strong><strong><em> tempdb</em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>go</em></strong><strong><em></em></strong></span></p>
<p>&nbsp;</p>
<p><span style="color: #0000ff;"><strong><em>declare</em></strong><strong><em> @enable int</em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>select</em></strong><strong><em> top 1 @enable = convert(int,value_in_use) from sys.configurations where name = 'default trace enabled'</em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>if</em></strong><strong><em> @enable = 1 --default trace is enabled</em></strong></span></p>
<p><span style="color: #0000ff;"><strong><em>begin</em></strong><strong><em> </em></strong></span></p>
<p><strong><em><span style="color: #0000ff;">declare @d1 datetime;declare @diff int;declare @indx int ;</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">declare @curr_tracefilename varchar(500); </span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">declare @base_tracefilename varchar(500); </span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">declare @temp_trace table (obj_name nvarchar(256) collate database_default,database_name nvarchar(256) collate database_default,start_time datetime, </span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; event_class int,event_subclass int,object_type int,server_name nvarchar(256) collate database_default,login_name nvarchar(256) collate database_default,</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; application_name nvarchar(256) collate database_default,ddl_operation nvarchar(40) collate database_default);</span></em></strong></p>
<p>&nbsp;</p>
<p><strong><em><span style="color: #0000ff;">select @curr_tracefilename = path from sys.traces where is_default = 1 ; set @curr_tracefilename = reverse(@curr_tracefilename)</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">select @indx&nbsp; = PATINDEX('%\%', @curr_tracefilename); set @curr_tracefilename = reverse(@curr_tracefilename)</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">set @base_tracefilename = LEFT( @curr_tracefilename,len(@curr_tracefilename) - @indx) + '\log.trc';</span></em></strong></p>
<p>&nbsp;</p>
<p><strong><em><span style="color: #0000ff;">insert into @temp_trace select ObjectName,DatabaseName,StartTime,EventClass,EventSubClass,ObjectType,ServerName,LoginName,ApplicationName,'temp' </span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">from ::fn_trace_gettable( @base_tracefilename, default ) where EventClass in (46,47,164) and EventSubclass = 0 and DatabaseID &lt;&gt; 2&nbsp; </span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">----------------------------------------------------------------------------------------------------------------------------------</span></em></strong></p>
<p><strong><em></em></strong><span style="color: #0000ff;"><strong><em>and</em></strong><strong><em> DatabaseName = 'SomeDB' -- &lt;&lt;&lt;======Specify the name of the database here, else comment this line to get details of databases</em></strong><strong><em></em></strong></span></p>
<p><strong><em><span style="color: #0000ff;">----------------------------------------------------------------------------------------------------------------------------------</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">update @temp_trace set ddl_operation = 'CREATE' where event_class = 46</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">update @temp_trace set ddl_operation = 'DROP' where event_class = 47</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">update @temp_trace set ddl_operation = 'ALTER' where event_class = 164</span></em></strong></p>
<p>&nbsp;</p>
<p><strong><em><span style="color: #0000ff;">select @d1 = min(start_time) from @temp_trace</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">set @diff= datediff(hh,@d1,getdate())</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">set @diff=@diff/24; </span></em></strong></p>
<p>&nbsp;</p>
<p><strong><em><span style="color: #0000ff;">select&nbsp; start_time as Event_Time,Database_name,Server_name,Login_name,Application_name,</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">--SQLInstance,</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DDL_Operation from @temp_trace where object_type not in (21587)</span></em></strong></p>
<p><strong><em><span style="color: #0000ff;">order by start_time&nbsp; desc</span></em></strong></p>
<p>&nbsp;</p>
<p><strong><em><span style="color: #0000ff;">end </span></em></strong></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/4075.clip_image00210_57C49381.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/4075.clip_5F00_image00210_5F00_57C49381.jpg"><img style="display: inline; border: 0px;" title="clip_image002[10]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/02/65/metablogapi/8228.clip_image00210_thumb_551E6881.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-02-65-metablogapi/8228.clip_5F00_image00210_5F00_thumb_5F00_551E6881.jpg" alt="clip_image002[10]" width="913" height="106" border="0" /></a></p>
<p><strong><em>Note:-&nbsp; The above query is the modified version of query which is executed in the background when we use SQL Server Reports (Method-1)</em></strong></p>
<p>&nbsp;</p>
<p><strong><span style="text-decoration: underline;">Author</span>:</strong></p>
<p><strong><span style="color: #0000ff;">Raghavendra Srinivasan</span> , Support Engineer, Microsoft India GTSC</strong></p>
<p><strong><span style="text-decoration: underline;">Reviewed by</span>:</strong></p>
<p><strong><span style="color: #0000ff;">Balmukund Lakhani</span>, Support Escalation Engineer, Microsoft India GTSC</strong></p>
<p><strong><br /></strong></p>
<p><strong><em><br /></em></strong></p>]]></content:encoded>
    </item>
    <item>
      <title>Snapshot agent fails with Error: 241, Severity: 16, State: 1 (Conversion failed when converting date and/or time from character string)</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlserverfaq/snapshot-agent-fails-with-error-241-severity-16-state-1-conversion-failed-when-converting-date-andor-time-from-character-string</link>
      <pubDate>Mon, 09 Feb 2015 19:42:32 GMT</pubDate>
      <dc:creator><![CDATA[Amvin [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sqlserverfaq/2015/02/09/snapshot-agent-fails-with-error-241-severity-16-state-1-conversion-failed-when-converting-date-andor-time-from-character-string/</guid>
      <description><![CDATA[ISSUE  Let’s say you are monitoring Replication Agent status and noticed that the Snapshot Agent...]]></description>
      <content:encoded><![CDATA[<p><b></b></p>  <p><b>ISSUE</b><b></b></p>  <p><font size="2" face="Segoe UI">Let’s say you are monitoring Replication Agent status and noticed that the Snapshot Agent has failed with the following error while generating a snapshot, particularly during creation of BCP files.</font></p>  <p><font size="2" face="Segoe UI">Error: 241, Severity: 16, State: 1</font></p>  <p><font size="2" face="Segoe UI">Conversion failed when converting date and/or time from character string.</font></p>  <p><font size="2" face="Segoe UI">To further investigate the above error and to understand which query is causing it, run a SQL Profiler trace in the background.</font></p>  <p><b>CAUSE</b><b></b></p>  <p><font size="2" face="Segoe UI">In order to understand the cause of the issue, it’s important to look at the schema structure and the column on which indexing is done. So let’s take a look at a schema script for a sample table “product” which has been published for Transactional Replication. </font></p>  <p><font size="2" face="Segoe UI">CREATE TABLE [dbo].[ product] (</font></p>  <p><font size="2" face="Segoe UI">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [ItemID] [int] IDENTITY(1, 1) NOT FOR REPLICATION NOT NULL</font></p>  <p><font size="2" face="Segoe UI">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ,[ReportDate] [date] NOT NULL</font></p>  <p><font size="2" face="Segoe UI">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ,[ProviderID] [int] NOT NULL</font></p>  <p><font size="2" face="Segoe UI">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ,[InvoiceImmediately] [bit] NOT NULL</font></p>  <p><font size="2" face="Segoe UI">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ,CONSTRAINT [PK_ItemUnbilled] PRIMARY KEY NONCLUSTERED ([ItemID] ASC)</font></p>  <p><font size="2" face="Segoe UI">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; )</font></p>  <p><font size="2" face="Segoe UI">CREATE CLUSTERED INDEX [IX_ItemUnbilled_ReportDate] ON [dbo].[ product] (</font></p>  <p><font size="2" face="Segoe UI">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [ReportDate] ASC</font></p>  <p><font size="2" face="Segoe UI">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ,[InvoiceImmediately] ASC</font></p>  <p><font size="2" face="Segoe UI">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ,[ProviderID] ASC</font></p>  <p><font size="2" face="Segoe UI">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; )</font></p>  <p><font size="2" face="Segoe UI">So the primary key (which is non-clustered index) is on [ItemID] column, and the clustered composite index is on three columns with the leading column as [ReportDate]. Before the error is raised, you will see something like the following query getting executed.</font></p>  <p><font size="2" face="Segoe UI">Select * from [dbo].[syncobj_0x4434414538323435] where ([ReportDate] is null) or ([ReportDate] &lt;= N'31/01/2014 00:00:00') order by [ReportDate] ASC,[InvoiceImmediately] ASC,[ProviderID] ASC</font></p>  <p><font size="2" face="Segoe UI">The “Where”&#160; clause we see here in the SELECT statement is because of BCP partitioning and the BCP file partitioning was done based on the [ReportDate] column (the leading column in the clustered index key). [ReportDate] column is of data type Date. The conversion fails because of the difference in language used by the account used to run the snapshot agent which was&#160; “UK English” - (dd/mm/yyyy)&#160; in this case, and the default language of SQL Server is “ US English “- (mm/dd/yyyy). </font></p>  <p><strong>WORKAROUNDS</strong></p>  <p><font size="2" face="Segoe UI">Now there are multiple easy workarounds available for the problem in question. I have listed the workarounds below.</font></p>  <p><b><u><font size="2" face="Segoe UI"></font></u></b></p>  <p><font size="2" face="Segoe UI">A) Use a different account, for which the default language setting is same as “ US ENGLISH” to run the Snapshot agent. Alternatively if possible, change the default language setting of the existing account to “ US English”.</font></p>  <p><font size="2" face="Segoe UI"><em>Note: This is the most preferred method.</em></font></p>  <p><font size="2" face="Segoe UI">B) You can disable BCP partitioning only for the problematic table by using static row filters. We do not go for BCP partitioning for tables that are filtered. Thus you can have a static row filter on the table in question but still retrieve all the rows without triggering BCP partition, using a query like, “Select * from table where 1=1”.</font></p>  <p><font size="2" face="Segoe UI"><em>Note: BCP partitioning will be disabled only for the table in question not the entire publication.</em></font></p>  <p><font size="2" face="Segoe UI">C) If @sync_method property of publication is set to “Native”, it’s recommended to change it to the default option of ”Concurrent”. This will be helpful if the snapshot agent is picking up a Date type column for BCP partitioning just because it has clustered index on it and the actual primary key column in the table is non-clustered. In the default setting, which is “Concurrent” , BCP partitioning happens only if the primary key column has a clustered index.</font></p>  <p><font size="2" face="Segoe UI">Exec sp_addpublication </font><a href="mailto:---@sync_method"><font size="2" face="Segoe UI">---@sync_method</font></a><font size="2" face="Segoe UI"> = N'concurrent'----</font></p>  <p><font size="2" face="Segoe UI"><em>Note: If the primary key column does not have clustered index and the @sync_method is set to “concurrent” then the BCP partitioning will be disabled for the entire publication. You might find snapshot agent taking more time to generate snapshot if there is any other big table in the same publication.</em></font></p>  <p><font size="2" face="Segoe UI">D) You can disable BCP partitioning for the entire publication by using the -EnbaleArticleBCPPartitioning 0 in the Snapshot Agent job step properties. Please refer to Paul Ibison’s blog for more details: </font><a href="https://www.replicationanswers.com/BCPPartitioning.asp"><font size="2" face="Segoe UI">https://www.replicationanswers.com/BCPPartitioning.asp</font></a><font size="2" face="Segoe UI">.</font></p>  <p><font size="2"><font face="Segoe UI"><strong><u>Disclaimer</u>: Links to third-party web sites are provided for information purposes only. Microsoft does not endorse nor support the content in third-party links. Microsoft is not responsible for the content of a third-party website. Privacy and security policies may differ from those practiced by Microsoft</strong>.</font></font></p>  <p><font size="2" face="Segoe UI"><em>Note: BCP partitioning will be disabled for the entire publication; you might find snapshot agent taking more time to generate snapshots if there is any other big table in the same publication.</em></font></p>  <p><font size="2" face="Segoe UI">E) The last option is to ensure that the primary key column has a clustered index and is not of data type Date.</font></p>  <p><font size="2" face="Segoe UI"><em>Note: This needs schema level changes. </em></font></p>  <p><font size="2" face="Segoe UI">While I strongly suggest using the first workaround because it’s the recommended approach, I am eager to hear about the workaround you choose for your environment and the reasons for your choice. So please state the details in the comments section. </font></p>  <p><strong></strong></p>  <p><strong>Author:</strong></p>  <p><strong>Madhumita Tripathy , Support Engineer, Microsoft India GTSC</strong></p>  <p><strong>Reviewed by:</strong></p>  <p><strong>Rishi Maini, Escalation Engineer, Microsoft India GTSC</strong></p>  <p><strong><strong>Vikas Rana</strong>, Technical Advisor, Microsoft India GTSC</strong></p>]]></content:encoded>
    </item>
  </channel>
</rss>