<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MS SQL &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/tag/ms-sql/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Wed, 04 Nov 2020 20:00:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>AWS, Windows: MS SQL 2017 with AlwaysOn (Named Instance, WSFC) on AWS</title>
		<link>https://blog.andreev.it/2019/07/windows-ms-sql-2017-with-alwayson-named-instance-wsfc-on-aws/</link>
					<comments>https://blog.andreev.it/2019/07/windows-ms-sql-2017-with-alwayson-named-instance-wsfc-on-aws/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Mon, 08 Jul 2019 20:16:10 +0000</pubDate>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[AlwaysOn]]></category>
		<category><![CDATA[MS SQL]]></category>
		<guid isPermaLink="false">https://blog.andreev.it/?p=5313</guid>

					<description><![CDATA[In this article, I&#8217;ll explain how to install and configure two Windows 2019 servers&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>In this article, I&#8217;ll explain how to install and configure two Windows 2019 servers running MS SQL 2017 Enterprise with <a href="https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/overview-of-always-on-availability-groups-sql-server?view=sql-server-2017" rel="noopener noreferrer" target="_blank">AlwaysOn</a>. The servers will have local storage only but you&#8217;ll still have HA. There are several prerequisites that you need in order to test this scenario. </p>
<ul>
&#8211; Functional AD and rights to create objects in AD<br />
&#8211; Unrestricted traffic access between the SQL nodes and AD (you can probably restrict the ports, but do your research)<br />
&#8211; Two AD accounts (an user account and a SQL service account)<br />
&#8211; Two extra IPs assigned to each SQL node<br />
&#8211; Proper DNS resolution in AWS and time synced between the nodes and DCs</ul>
</ul>
<h1>Domain controllers and AD</h1>
<p>I have two DCs running in two zones in the same region. Make sure that you can ping/resolve the servers by using only the short DNS name. E.g. My first domain controller is dc01. When I do <strong>ping dc02</strong> from dc01, it resolves fine. If not, check the DNS settings. You should also check the advanced DNS settings. Make sure that your domain is on the top. In my case, I have the DNS settings of dc01 pointing to itself and dc02. Notice ad-domain.local on top of other suffixes. <strong>AD-DOMAIN.LOCAL</strong> is the name of my domain. If you have the DNS suffixes configured on the VPC level, you don&#8217;t have to make this change. The only thing important is that you have a proper DNS resolution.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-01.png" alt="" width="1167" height="490" class="aligncenter size-full wp-image-8540" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-01.png 1167w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-01-300x126.png 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-01-1024x430.png 1024w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-01-768x322.png 768w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-01-585x246.png 585w" sizes="(max-width: 1167px) 100vw, 1167px" /></a><br />
Open up <strong>AD Users and Computers (dsa.msc)</strong> and create a single service account for the SQL servers. I&#8217;ll call it <strong>svc_sql</strong> and it should be a member of <strong>Domain Users</strong> only. The password should never expire. This account will run the SQL DB engine on SQL nodes.<br />
Then create an OU for the cluster object. In my case, I&#8217;ll create an OU called <strong>SQLCLUSTERS</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-02.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-02.png" alt="" width="362" height="278" class="aligncenter size-full wp-image-8541" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-02.png 362w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-02-300x230.png 300w" sizes="(max-width: 362px) 100vw, 362px" /></a><br />
Then create the name of your SQL cluster as a computer object and disable it.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-03.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-03.png" alt="" width="579" height="295" class="aligncenter size-full wp-image-8542" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-03.png 579w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-03-300x153.png 300w" sizes="(max-width: 579px) 100vw, 579px" /></a><br />
In <strong>AD Users and Computers</strong>, under the <strong>View </strong>menu, make sure that <strong>Advanced Features</strong> is enabled. Right-click the SQL cluster computer object and choose <strong>Properties</strong>, then click on <strong>Security </strong>tab and click <strong>Add</strong>. Type the name of the service account you just created and give it <strong>Full Control</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-04.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-04.png" alt="" width="460" height="528" class="aligncenter size-full wp-image-8543" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-04.png 460w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-04-261x300.png 261w" sizes="(max-width: 460px) 100vw, 460px" /></a><br />
We also need the cluster computer account to have rights to the OU. Right-click the OU that you just created, choose <strong>Properties </strong>and under the <strong>Security </strong>tab, click <strong>Advanced</strong>.<br />
You&#8217;ll see something like this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-05.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-05.png" alt="" width="763" height="520" class="aligncenter size-full wp-image-8544" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-05.png 763w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-05-300x204.png 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-05-585x399.png 585w" sizes="(max-width: 763px) 100vw, 763px" /></a><br />
Click <strong>Add </strong>and in the new dialog that shows up, in the upper left corner, click the link <strong>Select a principal</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-06.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-06.png" alt="" width="588" height="347" class="aligncenter size-full wp-image-8545" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-06.png 588w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-06-300x177.png 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-06-585x345.png 585w" sizes="(max-width: 588px) 100vw, 588px" /></a><br />
By default, computer object are not going to show up, so click on <strong>Object Types</strong> button, then check <strong>Computer </strong>and click <strong>OK </strong>to go back to the screen above.<br />
Type the name of the SQL cluster and click on <strong>Check Names</strong> to verify it.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-07.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-07.png" alt="" width="457" height="250" class="aligncenter size-full wp-image-8546" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-07.png 457w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-07-300x164.png 300w" sizes="(max-width: 457px) 100vw, 457px" /></a><br />
Click OK when it reminds you that the object is disabled. In the <strong>Permission Entry</strong> dialog box, make sure that the Type is set to <strong>Allow</strong>, and the <strong>Applies to</strong> is set to <strong>This object and all descendant objects</strong>. Finally, under <strong>Permissions</strong>, click on the <strong>Create Computer objects</strong> check box. Click<strong> OK</strong> until you close all open dialogs.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-08.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-08.png" alt="" width="899" height="553" class="aligncenter size-full wp-image-8547" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-08.png 899w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-08-300x185.png 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-08-768x472.png 768w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-08-585x360.png 585w" sizes="(max-width: 899px) 100vw, 899px" /></a><br />
The AD part is now complete.</p>
<h1>WSFC (Windows Server Failover Cluster)</h1>
<p>Now, we have to create and configure the failover cluster. I have two SQL nodes, <strong>node01 </strong>and <strong>node02</strong>. We have to install WSFC on each node, but before doing that, let&#8217;s add extra two IPs per node. In AWS console, on each SQL instance, click on the network adapter, usually called <strong>eth0</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-09.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-09.png" alt="" width="1015" height="284" class="aligncenter size-full wp-image-8548" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-09.png 1015w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-09-300x84.png 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-09-768x215.png 768w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-09-585x164.png 585w" sizes="(max-width: 1015px) 100vw, 1015px" /></a><br />
Click on the <strong>Interface ID</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-10.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-10.png" alt="" width="443" height="155" class="aligncenter size-full wp-image-8549" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-10.png 443w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-10-300x105.png 300w" sizes="(max-width: 443px) 100vw, 443px" /></a><br />
Then from the <strong>Actions </strong>drop down, click on <strong>Manage IP Addresses</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-11.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-11.png" alt="" width="695" height="265" class="aligncenter size-full wp-image-8550" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-11.png 695w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-11-300x114.png 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-11-585x223.png 585w" sizes="(max-width: 695px) 100vw, 695px" /></a><br />
Add two extra IPs per instance. You can choose DHCP provided IPs or manual. I decided to go with manual assignment. Make sure the IPs are in the same subnet as the primary and they are not in use.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-12.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-12.png" alt="" width="618" height="253" class="aligncenter size-full wp-image-8551" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-12.png 618w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-12-300x123.png 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-12-585x239.png 585w" sizes="(max-width: 618px) 100vw, 618px" /></a><br />
For <strong>node01</strong>, I&#8217;ll use <strong>192.168.1.60</strong> and <strong>192.168.1.61</strong> and for <strong>node02 </strong>I&#8217;ll use <strong>192.168.2.60</strong> and <strong>192.168.2.61</strong>. <strong>node01 </strong>and <strong>dc01 </strong>are in a <strong>192.168.1.0/24</strong> subnet and <strong>node02 </strong>and <strong>dc02 </strong>are in <strong>192.168.2.0/24</strong> subnet. Now, log to both nodes with an admin account and add the SQL service account <strong>svc_sql</strong> as a local administrator. Then log off and log back to SQL nodes as <strong>svc_sql</strong> service account.<br />
On both nodes, install the WSFC (Windows Server Failover Cluster) from an elevated PowerShell prompt and reboot.</p>
<pre class="brush: powershell; title: ; notranslate">
Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools
</pre>
<p>Once the instances come back, log as <strong>svc_sql</strong> and create the cluster. Open up an elevated command or PowerShell prompt and type <strong>cluadmin.msc</strong> (do this on one node, not both). In the wizard dialog box, click <strong>Browse </strong>and type the name of the nodes.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-13.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-13.png" alt="" width="533" height="260" class="aligncenter size-full wp-image-8552" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-13.png 533w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-13-300x146.png 300w" sizes="(max-width: 533px) 100vw, 533px" /></a><br />
The cluster wizard will do some pre-checks and if everything looks good click <strong>Next</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-14.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-14.png" alt="" width="534" height="259" class="aligncenter size-full wp-image-8553" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-14.png 534w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-14-300x146.png 300w" sizes="(max-width: 534px) 100vw, 534px" /></a><br />
Do not skip this part. Make sure you validate the cluster and you run all tests. It takes about a minute or two.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-15.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-15.png" alt="" width="527" height="115" class="aligncenter size-full wp-image-8554" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-15.png 527w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-15-300x65.png 300w" sizes="(max-width: 527px) 100vw, 527px" /></a><br />
You&#8217;ll see some warnings about the network, but you can ignore them. <a href="https://blog.andreev.it/wp-content/uploads/2019/07/Failover-Cluster-Validation-Report_htm50.zip" rel="noopener noreferrer" target="_blank">This </a>is how my report looked like. You&#8217;ll be able to enter the name of the cluster if everything is OK. In my case, the cluster name is the disabled computer object <strong>SQLCLUSTER01 </strong>that we created earlier.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-16.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-16.png" alt="" width="531" height="371" class="aligncenter size-full wp-image-8555" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-16.png 531w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-16-300x210.png 300w" sizes="(max-width: 531px) 100vw, 531px" /></a><br />
Make sure you uncheck the storage setting. We are using local storage, so there is nothing to add to the cluster as a resource.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-17.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-17.png" alt="" width="533" height="339" class="aligncenter size-full wp-image-8556" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-17.png 533w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-17-300x191.png 300w" sizes="(max-width: 533px) 100vw, 533px" /></a><br />
After a minute, you should get a greeting that the cluster is OK.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-18.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-18.png" alt="" width="536" height="349" class="aligncenter size-full wp-image-8557" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-18.png 536w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-18-300x195.png 300w" sizes="(max-width: 536px) 100vw, 536px" /></a><br />
Back in the cluster manager, you&#8217;ll see this mess. Don&#8217;t worry.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-19.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-19.png" alt="" width="920" height="587" class="aligncenter size-full wp-image-8558" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-19.png 920w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-19-300x191.png 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-19-768x490.png 768w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-19-585x373.png 585w" sizes="(max-width: 920px) 100vw, 920px" /></a><br />
At the bottom of the cluster manager, right click the first node and choose <strong>Properties</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-20.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-20.png" alt="" width="570" height="187" class="aligncenter size-full wp-image-8559" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-20.png 570w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-20-300x98.png 300w" sizes="(max-width: 570px) 100vw, 570px" /></a><br />
How do you know which one is which? Once you open the properties, look at the <strong>Network </strong>under the <strong>General </strong>tab. Based on the subnet, you&#8217;ll have to assign the IP that belongs to that subnet. So, in my case this is how it looked like before I made the change.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-21.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-21.png" alt="" width="400" height="553" class="aligncenter size-full wp-image-8560" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-21.png 400w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-21-217x300.png 217w" sizes="(max-width: 400px) 100vw, 400px" /></a><br />
I know that <strong>192.168.2.0/24</strong> belongs to <strong>node02</strong>, so I&#8217;ve changed the settings from DHCP to Static IP and added <strong>192.168.2.60</strong>. Remember this IP? It was the first one that we added to node02. Scroll up if you forgot.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-22.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-22.png" alt="" width="396" height="555" class="aligncenter size-full wp-image-8561" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-22.png 396w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-22-214x300.png 214w" sizes="(max-width: 396px) 100vw, 396px" /></a><br />
Do the same for the 2nd entry. This time you have to add <strong>192.168.1.60</strong> because the subnet is <strong>192.168.1.0/24</strong>. Then, bring the cluster online.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-23.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-23.png" alt="" width="565" height="318" class="aligncenter size-full wp-image-8562" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-23.png 565w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-23-300x169.png 300w" sizes="(max-width: 565px) 100vw, 565px" /></a><br />
Now, you can install the SQL server. </p>
<h1>SQL Server installation</h1>
<p>As I mentioned earlier, make sure you have correct DNS settings and the time is in sync with AD. Before you install MS SQL, make sure you have your partitions ready. They don&#8217;t have to be like this, you can use C:\ only for everything, but ask your DBA how they want to carve the space for the DB. I am using the trial version downloaded from <a href="https://www.microsoft.com/en-us/sql-server/sql-server-downloads" rel="noopener noreferrer" target="_blank">here</a>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-24.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-24.png" alt="" width="754" height="207" class="aligncenter size-full wp-image-8563" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-24.png 754w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-24-300x82.png 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-24-585x161.png 585w" sizes="(max-width: 754px) 100vw, 754px" /></a><br />
Run the installation on both nodes using the service account <strong>svc_sql</strong>. You made this a local admin, didn&#8217;t you? Click on <strong>Installation </strong> on the left side and the first option for a <strong>new SQL Server stand-alone</strong>&#8230;<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-25.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-25.jpg" alt="" width="743" height="269" class="aligncenter size-full wp-image-8564" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-25.jpg 743w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-25-300x109.jpg 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-25-585x212.jpg 585w" sizes="(max-width: 743px) 100vw, 743px" /></a><br />
Choose license.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-26.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-26.jpg" alt="" width="324" height="161" class="aligncenter size-full wp-image-8565" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-26.jpg 324w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-26-300x149.jpg 300w" sizes="(max-width: 324px) 100vw, 324px" /></a><br />
Accept the license terms and use or do not use <strong>Microsoft Update</strong> for SQL updates.<br />
Ignore the warning for the firewall.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-27.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-27.jpg" alt="" width="477" height="141" class="aligncenter size-full wp-image-8566" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-27.jpg 477w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-27-300x89.jpg 300w" sizes="(max-width: 477px) 100vw, 477px" /></a><br />
Check the <strong>Database Engine Service</strong>, <strong>SQL Server Replication</strong>&#8230;<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-28.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-28.jpg" alt="" width="283" height="88" class="aligncenter size-full wp-image-8567" /></a><br />
&#8230;scroll down and check <strong>Client Tools Connectivity</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-29.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-29.jpg" alt="" width="276" height="54" class="aligncenter size-full wp-image-8568" /></a><br />
Click on <strong>Named instance</strong> and type your name. In my case it&#8217;s <strong>SQL2017</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-30.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-30.jpg" alt="" width="316" height="165" class="aligncenter size-full wp-image-8569" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-30.jpg 316w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-30-300x157.jpg 300w" sizes="(max-width: 316px) 100vw, 316px" /></a><br />
Leave the <strong>Service Accounts</strong> as is. We&#8217;ll change one of them later.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-31.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-31.jpg" alt="" width="579" height="240" class="aligncenter size-full wp-image-8570" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-31.jpg 579w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-31-300x124.jpg 300w" sizes="(max-width: 579px) 100vw, 579px" /></a><br />
Under <strong>Server Configuration</strong> tab, use <strong>Windows authentication mode</strong> and click <strong>Add Current User</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-32.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-32.jpg" alt="" width="586" height="426" class="aligncenter size-full wp-image-8571" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-32.jpg 586w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-32-300x218.jpg 300w" sizes="(max-width: 586px) 100vw, 586px" /></a><br />
On the <strong>Data Directories</strong> tab in the same dialog you can change the disk destinations. If you have just one <strong>C:\</strong> partition you can skip this part. If not, map the directories here. Here are mine.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-33.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-33.png" alt="" width="582" height="241" class="aligncenter size-full wp-image-8572" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-33.png 582w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-33-300x124.png 300w" sizes="(max-width: 582px) 100vw, 582px" /></a><br />
And for <strong>TempDB</strong> on the next tab in the same dialog.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-34.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-34.png" alt="" width="576" height="415" class="aligncenter size-full wp-image-8573" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-34.png 576w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-34-300x216.png 300w" sizes="(max-width: 576px) 100vw, 576px" /></a><br />
Proceed to <strong>Install</strong> until the installation completes successfully.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-35.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-35.jpg" alt="" width="599" height="143" class="aligncenter size-full wp-image-8574" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-35.jpg 599w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-35-300x72.jpg 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-35-585x140.jpg 585w" sizes="(max-width: 599px) 100vw, 599px" /></a></p>
<h2>SQL Management Tools (optional)</h2>
<p>This step is optional. If you have <strong>SSMS </strong>already installed, you can skip this part. If not, install it on a node, both or any client workstation. From the same setup menu, install SQL Management Tools (third from the top). This will take you to a MS web site where you can download the latest <strong>SMSS</strong> (SQL Server Management Studio).<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-36.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-36.jpg" alt="" width="743" height="269" class="aligncenter size-full wp-image-8575" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-36.jpg 743w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-36-300x109.jpg 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-36-585x212.jpg 585w" sizes="(max-width: 743px) 100vw, 743px" /></a></p>
<h2>SQL service account change</h2>
<p>Before you reboot, let&#8217;s change the account that runs SQL. This is mandatory for a SQL cluster. DO NOT change the account from the <strong>Services </strong>console, instead open <strong>SQL 2017 Configuration Manager</strong>.<br />
Do this on both nodes. Select where it says <strong>SQL Server Services</strong> on the left and then right-click on <strong>SQL Server (SQL2017)</strong> on the right and choose <strong>Properties</strong>.<br />
Enter the SQL service account, its password and click <strong>Apply</strong>. This will reset the SQL service and change it to run under the domain service account. Do not reboot yet.</p>
<h1>Dynamic ports and firewall</h1>
<p>Because we are using a named SQL instance, the DB engine assigns a random dynamic port for the listener. Instead of opening a range of ports on the firewall, we can restrict the listener to a static port and then open the firewall for that port only. Do this on both nodes. In the same <strong>SQL 2017 Configuration Manager</strong>, look for <strong>SQL Server Network Configuration</strong> on the left, expand it and select <strong>Protocols for SQL2017</strong> or whatever you named your instance. Right-click where it says <strong>TCP/IP</strong> on the right and choose <strong>Properties</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-37.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-37.jpg" alt="" width="492" height="235" class="aligncenter size-full wp-image-8576" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-37.jpg 492w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-37-300x143.jpg 300w" sizes="(max-width: 492px) 100vw, 492px" /></a><br />
Click on the second tab <strong>IP Addresses</strong> and scroll all the way down where it says <strong>TCP Dynamic Ports</strong>. Delete that value, leave it blank and in the next field <strong>TCP Port</strong> below, enter a random TCP port from <strong>49152-65535</strong>. I&#8217;ll use <strong>50000 </strong>for both nodes. You need to restart the SQL service for this change to take effect, but we&#8217;ll reboot, so no need for that. But, if you have your Windows Firewall enabled, you have to open these TCP ports. Run these command from an elevated PowerShell prompt.</p>
<pre class="brush: bash; title: ; notranslate">
New-NetFirewallRule -Name &quot;SQL2017 Named Instance (in)&quot; -Description &quot;SQL2017 Named Instance&quot; `
-DisplayName &quot;SQL2017 Named Instance&quot; -Enabled:True -Profile Domain,Public,Private `
-Direction Inbound -Action Allow -Protocol TCP -LocalPort 50000
New-NetFirewallRule -Name &quot;SQL Server Rule (in)&quot; -Description &quot;SQL Server Rule&quot; `
-DisplayName &quot;SQL Rule&quot; -Enabled:True -Profile Domain,Public,Private `
-Direction Inbound -Action Allow -Protocol TCP -LocalPort 1433
New-NetFirewallRule -Name &quot;SQL Server Browser Rule (in)&quot; -Description &quot;SQL Server Browser Rule&quot; `
-DisplayName &quot;SQL Browser Rule&quot; -Enabled:True -Profile Domain,Public,Private `
-Direction Inbound -Action Allow -Protocol UDP -LocalPort 1434
New-NetFirewallRule -Name &quot;SQL Server AlwaysOn Replication (in)&quot; -Description &quot;SQL Server AlwaysOn Replication&quot; `
-DisplayName &quot;SQL Server AlwaysOn Replication&quot; -Enabled:True -Profile Domain,Public,Private `
-Direction Inbound -Action Allow -Protocol TCP -LocalPort 5022
</pre>
<p>Now, you can reboot.</p>
<h1>AlwaysOn</h1>
<p>Log as the SQL service account <strong>svc_sql</strong> and open <strong>SQL Configuration Manager</strong>. You have to do this on both nodes. Similarly to what you did when you change the SQL service account, do the same.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-38.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-38.jpg" alt="" width="856" height="455" class="aligncenter size-full wp-image-8577" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-38.jpg 856w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-38-300x159.jpg 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-38-768x408.jpg 768w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-38-585x311.jpg 585w" sizes="(max-width: 856px) 100vw, 856px" /></a><br />
Select <strong>SQL Server Services</strong>, right-click <strong>SQL Server (SQL2017)</strong> and check <strong>Enable AlwaysOn Availability Groups</strong> under <strong>AlwaysOn High Availability</strong> tab.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-39.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-39.jpg" alt="" width="797" height="331" class="aligncenter size-full wp-image-8578" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-39.jpg 797w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-39-300x125.jpg 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-39-768x319.jpg 768w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-39-585x243.jpg 585w" sizes="(max-width: 797px) 100vw, 797px" /></a><br />
Restart the SQL service on both nodes. Once completed, open SSMS, connect to a node and create a new database.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-40.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-40.jpg" alt="" width="361" height="264" class="aligncenter size-full wp-image-8579" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-40.jpg 361w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-40-300x219.jpg 300w" sizes="(max-width: 361px) 100vw, 361px" /></a><br />
I&#8217;ll name my database <strong>MyDB</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-41.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-41.jpg" alt="" width="501" height="205" class="aligncenter size-full wp-image-8580" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-41.jpg 501w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-41-300x123.jpg 300w" sizes="(max-width: 501px) 100vw, 501px" /></a><br />
Make sure you backup the database. You can&#8217;t proceed without this step.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-42.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-42.jpg" alt="" width="514" height="250" class="aligncenter size-full wp-image-8581" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-42.jpg 514w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-42-300x146.jpg 300w" sizes="(max-width: 514px) 100vw, 514px" /></a><br />
Little further below, right-click on <strong>Always On High Availability</strong> and click on <strong>New Availability Group Wizard</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-43.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-43.jpg" alt="" width="420" height="101" class="aligncenter size-full wp-image-8582" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-43.jpg 420w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-43-300x72.jpg 300w" sizes="(max-width: 420px) 100vw, 420px" /></a><br />
Specify a name for the availability group.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-44.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-44.jpg" alt="" width="574" height="198" class="aligncenter size-full wp-image-8583" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-44.jpg 574w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-44-300x103.jpg 300w" sizes="(max-width: 574px) 100vw, 574px" /></a><br />
Select the database that we just created.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-45.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-45.jpg" alt="" width="582" height="131" class="aligncenter size-full wp-image-8584" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-45.jpg 582w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-45-300x68.jpg 300w" sizes="(max-width: 582px) 100vw, 582px" /></a><br />
Click on <strong>Add Replica</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-46.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-46.jpg" alt="" width="581" height="288" class="aligncenter size-full wp-image-8585" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-46.jpg 581w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-46-300x149.jpg 300w" sizes="(max-width: 581px) 100vw, 581px" /></a><br />
Connect to node02.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-47.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-47.jpg" alt="" width="574" height="361" class="aligncenter size-full wp-image-8586" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-47.jpg 574w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-47-300x189.jpg 300w" sizes="(max-width: 574px) 100vw, 574px" /></a><br />
I want automatic failover which means it&#8217;s a synchronous commit.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-48.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-48.jpg" alt="" width="580" height="218" class="aligncenter size-full wp-image-8587" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-48.jpg 580w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-48-300x113.jpg 300w" sizes="(max-width: 580px) 100vw, 580px" /></a><br />
Choose <strong>Automatic Seeding</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-49.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-49.jpg" alt="" width="589" height="467" class="aligncenter size-full wp-image-8588" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-49.jpg 589w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-49-300x238.jpg 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-49-585x464.jpg 585w" sizes="(max-width: 589px) 100vw, 589px" /></a><br />
Don&#8217;t worry about the listener.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-50.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-50.jpg" alt="" width="577" height="221" class="aligncenter size-full wp-image-8589" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-50.jpg 577w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-50-300x115.jpg 300w" sizes="(max-width: 577px) 100vw, 577px" /></a><br />
After 10-20 seconds the configuration should complete.<br />
Now, we need to add a listener. Expand the <strong>Availability Groups</strong>, right-click <strong>Availability Group Listeners</strong> and select <strong>Add Listener</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-51.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-51.jpg" alt="" width="382" height="218" class="aligncenter size-full wp-image-8590" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-51.jpg 382w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-51-300x171.jpg 300w" sizes="(max-width: 382px) 100vw, 382px" /></a><br />
Give listener a name (in my case <strong>MyListener</strong>), you can choose a port (I used the default <strong>1433</strong>, you can choose a random port but don&#8217;t forget to open the firewall) and add the other two IPs as static IPs.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-52.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-52.jpg" alt="" width="506" height="195" class="aligncenter size-full wp-image-8591" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-52.jpg 506w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-52-300x116.jpg 300w" sizes="(max-width: 506px) 100vw, 506px" /></a><br />
Right-click the availability group and click on <strong>Show Dashboard</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-53.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-53.jpg" alt="" width="852" height="504" class="aligncenter size-full wp-image-8592" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-53.jpg 852w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-53-300x177.jpg 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-53-768x454.jpg 768w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-53-585x346.jpg 585w" sizes="(max-width: 852px) 100vw, 852px" /></a><br />
Everything should be with green checkmarks and both states should be synchronized. The availability group (and the database) are configured for automatic failover, but you can do manual failover if you want. Right-click the availability group and click on <strong>Failover</strong>. This is how my manual failover looks like.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-54.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-54.jpg" alt="" width="576" height="202" class="aligncenter size-full wp-image-8593" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-54.jpg 576w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-54-300x105.jpg 300w" sizes="(max-width: 576px) 100vw, 576px" /></a><br />
At this point you have a fully functional AlwaysOn cluster. </p>
<h1>Test the failover (optional)</h1>
<p>We&#8217;ll use a sample populated table to run some queries from PowerShell. Then, we&#8217;ll stop one node and watch the outcome. In order to do the test, open up SMSS, log as <strong>svc_sql</strong> and connect to the listener directly.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-55.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-55.jpg" alt="" width="479" height="227" class="aligncenter size-full wp-image-8594" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-55.jpg 479w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-55-300x142.jpg 300w" sizes="(max-width: 479px) 100vw, 479px" /></a><br />
Click on <strong>New Query</strong> from the top.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-56.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-56.jpg" alt="" width="394" height="236" class="aligncenter size-full wp-image-8595" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-56.jpg 394w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-56-300x180.jpg 300w" sizes="(max-width: 394px) 100vw, 394px" /></a><br />
Insert these statements. They&#8217;ll create a SQL login mapped from the domain name (in my case <strong>klimenta</strong>) and a table in the <strong>MyDB </strong>database called <strong>COLORS</strong>. Replace the values that match your domain name and the database. Execute the first part (<strong>CREATE LOGIN</strong>) on <strong>node02 </strong>too.</p>
<pre class="brush: sql; title: ; notranslate">
CREATE LOGIN &#x5B;AD-DOMAIN\klimenta]  
    FROM WINDOWS  
    WITH DEFAULT_DATABASE = &#x5B;MyDB];
USE MyDB;
CREATE TABLE COLORS (ID INT, NAME VARCHAR(10));
INSERT INTO COLORS VALUES(1,'RED');
INSERT INTO COLORS VALUES(2,'YELLOW');
INSERT INTO COLORS VALUES(3,'BLUE');
INSERT INTO COLORS VALUES(4,'WHITE');
GO
</pre>
<p>Double-click the login that you just created, click on <strong>User Mapping</strong> and put a checkmark next to <strong>MyDB</strong> database.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-57.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-57.jpg" alt="" width="698" height="321" class="aligncenter size-full wp-image-8596" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-57.jpg 698w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-57-300x138.jpg 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-57-585x269.jpg 585w" sizes="(max-width: 698px) 100vw, 698px" /></a><br />
Right-click the database, choose <strong>Properties </strong>then click on <strong>Permissions</strong>. Select the username and make sure you have <strong>Connect </strong>and <strong>Select </strong>permissions.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-58.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-58.jpg" alt="" width="754" height="465" class="aligncenter size-full wp-image-8597" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-58.jpg 754w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-58-300x185.jpg 300w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-58-585x361.jpg 585w" sizes="(max-width: 754px) 100vw, 754px" /></a><br />
From a separate workstation/server, you can use even the domain controller, log as the username (<strong>klimenta</strong>) that you just granted right to the MyDB database. Open up PowerShell ISE and run this script. Replace the values for the listener and the database. It&#8217;s a script that connects to the database and spits the contect of the COLORS table indefinitely. Use CTRL-C to break.</p>
<pre class="brush: powershell; title: ; notranslate">
$Server = 'tcp:mylistener,1433'    
$database = 'MyDB'
$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString = &quot;server=$($Server);database=$($Database);trusted_connection=true;MultiSubnetFailover=True;&quot;
$Connection.Open()
$Command = New-Object System.Data.SQLClient.SQLCommand
$Command.Connection = $Connection
$x=0
while ($true) {
    $Command.CommandText = 'SELECT * FROM COLORS'
    $Reader = $Command.ExecuteReader()
    $Datatable = New-Object System.Data.DataTable
    $Datatable.Load($Reader)
    $Datatable
    Start-Sleep -s 5
    Write-Host($x, &quot;---&quot;)
    $x++;
}
$Connection.Close()  
</pre>
<p>Once you see the output, shutdown the primary node or do a manual failover. You&#8217;ll notice that there is no interruption in the program flow. The only thing that changes is the IP of the listener.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/07/P132-59.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/07/P132-59.jpg" alt="" width="395" height="362" class="aligncenter size-full wp-image-8598" srcset="https://blog.andreev.it/wp-content/uploads/2019/07/P132-59.jpg 395w, https://blog.andreev.it/wp-content/uploads/2019/07/P132-59-300x275.jpg 300w" sizes="(max-width: 395px) 100vw, 395px" /></a></p>
<h1>Links</h1>
<p><a href="https://youtu.be/GM7H9fba9cQ" rel="noopener noreferrer" target="_blank">YouTube (AWS)</a><br />
<a href="https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/overview-of-always-on-availability-groups-sql-server?view=sql-server-2017" rel="noopener noreferrer" target="_blank">Microsoft</a><br />
<a href="https://www.red-gate.com/simple-talk/sql/database-administration/the-posh-dba-accessing-sql-server-from-powershell/" rel="noopener noreferrer" target="_blank">PowerShell</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2019/07/windows-ms-sql-2017-with-alwayson-named-instance-wsfc-on-aws/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AWS: Restore MS SQL database to RDS</title>
		<link>https://blog.andreev.it/2017/08/109-aws-restore-ms-sql-database-rds/</link>
					<comments>https://blog.andreev.it/2017/08/109-aws-restore-ms-sql-database-rds/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Sat, 05 Aug 2017 22:32:25 +0000</pubDate>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[MS SQL]]></category>
		<category><![CDATA[RDS]]></category>
		<category><![CDATA[restore]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=3099</guid>

					<description><![CDATA[I had to migrate a SQL 2014 database from our on-prem environment to AWS.&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>I had to migrate a SQL 2014 database from our on-prem environment to AWS. The requirement was to use RDS. So, these are the steps that I&#8217;ve taken in order to successfully migrate the database. You can also check the official AWS link <a href="http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Procedural.Importing.html" target="_blank" rel="noopener noreferrer">here</a>. </p>
<p>First, take a backup of the existing database in <strong>BAK </strong>format. In my case for the purpose of this blog, I&#8217;ve backed up my vCenter database called <strong>VCDB </strong>in a file called <strong>VCDB.BAK</strong>. Once you have the file, create a S3 bucket in AWS with the default settings and upload the BAK file there. In my case the S3 bucket was named <strong>restoremybackup</strong>.<br />
Next, make sure you have access to a Windows server with SQL Management Studio installed, either in AWS or on-prem, but this server will need to talk to the RDS database over port 1433 TCP. I built a server in AWS and installed the SQL Management Studio, which is a free download. Make sure that you have a security group in place that allows port 1433. We will use this security group to assign it to the RDS instance. I&#8217;ve created a new security group called <strong>sgAllowSQLAccess</strong>. For the source, type the IP of the server with SQL Management Studio or the security group itself. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-01.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-01.png" alt="" width="681" height="375" class="aligncenter size-full wp-image-7650" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-01.png 681w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-01-300x165.png 300w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-01-585x322.png 585w" sizes="(max-width: 681px) 100vw, 681px" /></a><br />
Then, go to RDS and create an <strong>Option Group</strong>. Name the <strong>Option Group</strong>, in my case it&#8217;s <strong>ogSQL2014Restore</strong>, choose the engine and the version. I am using <strong>sqlserver-se</strong> which is <strong>SQL Standard Edition</strong> and the version is <strong>12.00</strong> which is <strong>MS SQL 2014</strong>. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-02.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-02.png" alt="" width="684" height="282" class="aligncenter size-full wp-image-7651" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-02.png 684w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-02-300x124.png 300w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-02-585x241.png 585w" sizes="(max-width: 684px) 100vw, 684px" /></a><br />
Once created, select your <strong>Option Group</strong> and click on <strong>Add Option</strong>. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-03.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-03.png" alt="" width="672" height="288" class="aligncenter size-full wp-image-7652" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-03.png 672w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-03-300x129.png 300w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-03-585x251.png 585w" sizes="(max-width: 672px) 100vw, 672px" /></a><br />
Choose <strong>SQLSERVER_BACKUP_RESTORE</strong>, then click on <strong>Create a New Role</strong>. For the role, use a name, in my case it&#8217;s <strong>iamRestoreSQLBackup</strong>. Then type the name of the S3 bucket that you just created and make sure that you select <strong>Apply Immediately &#8211; yes</strong>.<br />
Then click on <strong>Add Option</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-04.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-04.png" alt="" width="636" height="316" class="aligncenter size-full wp-image-7653" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-04.png 636w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-04-300x149.png 300w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-04-585x291.png 585w" sizes="(max-width: 636px) 100vw, 636px" /></a><br />
Now, it&#8217;s time to create the RDS database. Launch a new RDS instance and use the parameters that suit your needs. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-05.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-05.png" alt="" width="647" height="566" class="aligncenter size-full wp-image-7654" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-05.png 647w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-05-300x262.png 300w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-05-585x512.png 585w" sizes="(max-width: 647px) 100vw, 647px" /></a><br />
For the next set of options, choose your preferred settings, but make sure that you assign the <strong>Security Group</strong> that we just created and the <strong>Option Group</strong> that we also created. In my case it looks like this. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-06.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-06.png" alt="" width="571" height="706" class="aligncenter size-full wp-image-7655" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-06.png 571w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-06-243x300.png 243w" sizes="(max-width: 571px) 100vw, 571px" /></a><br />
Once the RDS it&#8217;s in available state, try to telnet to port 1433 to the RDS endpoint from the Windows server where you have the SQL Management Studio installed. If everything is OK, you are ready to restore the database. In SQL Management Studio, select a <strong>New Query</strong> and type the following. </p>
<pre class="brush: sql; title: ; notranslate">
exec msdb.dbo.rds_restore_database 
        @restore_db_name='database_name', 
        @s3_arn_to_restore_from='arn:aws:s3:::bucket_name/file_name_and_extension';
</pre>
<p>Replace <strong>&#8216;database_name&#8217;</strong> and <strong>&#8216;bucket_name/file_name_and_extenstion&#8217;</strong> with your values. In my case, they were <strong>VCDB </strong>and <strong>restoremybackup/VCDB.BAK</strong>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2017/08/109-aws-restore-ms-sql-database-rds/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
