Tuesday, December 3, 2019

Extend Windows Server 2019 Trial to longer use

Microsoft allows to extend trial license up to six times for Windows Server 2019. That's 180 days x 6 = 3 years. So if you run into an expired license give this tip a try before loading up your Installation media.

How do you find out your Windows is expired? You probably first notice a message at the lower right corner on your desktop. It tells you your Windows license is expired. Hence your Windows becomes inactivated as you can see from Control Panel -> System. Perhaps you first are greeted with a message popping out saying "shutting down". Thinking that might be a mandatory restart due to Windows security patches and updates, you patiently wait for the server to come back online. You login in again, poking around and again the concerning "shutting down" message shows up in about half an hour. Don't panic. There's nothing wrong with your server. You simply need to extend its lifetime.


Open a Powershell windows or command line, type slmgr -dlv to confirm there are 6 rearm counts in total. And in the screenshot below I have 6 times remaining.


Type slmgr -rearm to extend license by 180 days. This will consume one rearm count. Restart the server.


After restarting your server you can check it out by typing slmgr -dli.


Check counts again with slmgr -dlv. Notice it's now 5 rearm counts.


You can also confirm this by looking at Control Panel -> System that will say Windows is activated. The desktop message also changes to "Windows license valid for 180 days".


Disclaimer: Everything this post describes is for non production use.






Thursday, August 29, 2019

Azure 2# - Join On-Premise and Azure data via SQL 2017 PolyBase

Starting with SQL Server 2016 PolyBase was introduced as an easy way to query semi-structured and non-structured data sources with T-SQL. In today's post I'm creating a demo to show this feature.

Step 1. Install and configure PolyBase

First of all, we have to install PolyBase. It is a feature that can be checked during SQL Server installation.


Make sure you install Java Runtime Environment (JRE 7 or above) in advance or your PolyBase installation will fail. JRE is needed to connect to Hadoop. In SQL Server 2019 RC1 the prerequisite of JRE has been removed. Instead you're taken to a page that downloads and install JRE 11. 


After SQL Server gets installed go into a query session and run the following commands:

EXEC sp_configure 'show advanced option', '1';
RECONFIGURE;
GO

EXEC sp_configure 'hadoop connectivity', 4;
GO

Note you must restart SQL Server service in order for the above configuration to take effect (run value turns from 1 into 4). You can confirm PolyBase is installed by executing the select query below. It should return 1.

select SERVERPROPERTY ('IsPolyBaseInstalled')

Step 2. Download and import source file

We wish to use unstructured non-relational data source. In searching for free samples of comma delimited csv files I stumbled upon this web site http://eforexcel.com/wp/downloads-18-sample-csv-files-data-sets-for-testing-sales/

It seems 1 million records is suitable for our demo. So go ahead downloading that file highlighted in yellow circle.


In SSMS, connect to your SQL 2017 server. You can use any database. I happen to have a restored copy of AdventureWorks2017 so let's import the downloaded CSV file into table named "1000000 Sales Records". Make sure data source is flat file and tick the file types to include .csv files. Check columns and preview to make sure the result looks OK.








Step 3. Store CSV file in Azure container

Login in Microsoft Azure Portal. Create a storage account by following this order:

Storage -> Storage Accounts -> New storage Account "polybasestoragesqlshack" -> Blob Containers -> mycontainer01

When the container is ready, click on Upload button to transfer the csv file to cloud.



Step 4. Configure PolyBase query

Follow the steps below to set up PolyBase. Note the password is shown as pound signs for obvious reason. Replace it with your own password.

USE AdventureWorks2017
GO

CREATE MASTER KEY ENCRYPTION BY PASSWORD='########';
GO

CREATE DATABASE SCOPED CREDENTIAL mycredential
WITH IDENTITY = 'credential', Secret = 'YMmkZJR2P4XwmIUhElJeZ88SpYaI3l/LR6BE7vbbPoyREvMYYHb5ioisNu6SXh1BeUbF1KJKuvlPc/RCfGbQYw=='
GO

The secret hash is copied from Azure Portal. You can obtain it by either way:

Portal: Click on storage account access keys, then copy the values from Key1.

MASE (Microsoft Azure Storage Explorer): Click on storage account properties, then copy the values of Primary Key.





CREATE EXTERNAL DATA SOURCE mycustomers
WITH (
    TYPE = HADOOP,
    LOCATION = 'wasbs://mycontainer01@polybasestoragesqlshack.blob.core.windows.net/',
    CREDENTIAL = mycredential
);


CREATE EXTERNAL FILE FORMAT csvformat 
WITH ( 
    FORMAT_TYPE = DELIMITEDTEXT, 
    FORMAT_OPTIONS ( 
        FIELD_TERMINATOR = ','
    ) 
);

CREATE EXTERNAL TABLE ExtTblSalesRecords ( 
Region varchar(2000),
Country varchar(2000),
[Item Type] varchar(2000),
[Sales Channel] varchar(2000),
[Order Priority] varchar(2000),
[Order Date] nvarchar(100),
[Order ID] nvarchar(100),
[Ship Date] nvarchar(100),
[Units Sold] nvarchar(100),
[Unit Price] nvarchar(100),
[Unit Cost] nvarchar(100),
[Total Revenue] nvarchar(100),
[Total Cost] nvarchar(100),
[Total Profit] nvarchar(100) ) 
WITH ( 
    LOCATION = '/1000000 Sales Records.csv', --  file is in the root
    DATA_SOURCE = mycustomers, 
    FILE_FORMAT = csvformat)

Finally we can run a query that brings local SQL table and Azure Blob data table together. The below record set is consisted of 5 rows of sales orders from Asia (Azure Blob) and 10 rows of sales orders from other non-Asia regions (on-premise).

SELECT TOP 5 * 
FROM [AdventureWorks2017].[dbo].[ExtTblSalesRecords] 
WHERE Region IN ('Asia')
UNION 
SELECT TOP 10 * FROM [AdventureWorks2017].[dbo].[1000000 Sales Records] 
WHERE Region NOT IN ('Asia')



Saturday, August 24, 2019

Azure #1 - Create a Windows 2019 VM in Microsoft Azure

This is the first post of an upcoming series for Microsoft Azure.

Assume you've got an Azure subscription account. The next first thing to do is to create a resource group. Login in to Azure Portal page https://portal.azure.com/. Click to create a resource at upper left-hand corner. A "New" page appears in the right pane. Click "Windows Server 2016 Datacenter" to launch vm creation page. This page has many vm related tabs. I'll go over each tab in the following sections.


On the first "Basics" tab, choose subscription. Underneath it either pick a resource group from the drop down list or click on "Create new" to create a new resource group. We are creating a new resource so fill in the pop-up windows with Name "ResGrp_Win2019". Hit OK. 


Next we need to give the VM a machine name. Note there're some restrictions for naming. You'll see them on the right side. I'd like to call it "TstSrvSQL2019_A". Unfortunately it didn't seem to accept underscore inside the name. The guide only says it doesn't allow an underscore at the beginning. More interestingly, the red error message does not sound like an error. If I remove "_" then all is green. I guess we just hit a small bug but let's move on.



Choose a Region from a list of 30+ options. We also want to create an Availability Set. Since no existing set exists we click on "Create new". In the right side pane fill in set name as "Set_Win_US_East" and leave default numbers of machines as is.




Next choose the right size for this VM. Then click OK.



In setting up administrator account, notice you cannot use "Admin" or "Administrator" as they are considered reserved words. For password, it must be between 12 - 123 characters long. So we create  "VMADMIN" to allow RDP access to all VMs we create. Select RDP port to allow inbound traffic. 

So much for the basics. Now click on "Next:Disks >" at the bottom of the page to move on to next section. 


On the "Disks" tab, there're fewer items to choose. We pick Standard hard disks instead of SSD disks. Then switch to networking tab. 



On networking tab, create a new vNetwork. Accept default vnet name. Choose both address space and subnets. Click OK.




Click on "Next:Management >" to move on to Mgt. tab. Accept default account for diagnostics storage. Enable backup. Create a new vault "vault888" and assign existing BackupGrp to it, Use Daily Backup Policy.


Temporarily pick rd as a tag on the "Tags" tab for now. Click "Review + create" to review all settings before creating the actual VM.



At last click on "Create" to kick off the VM building process. A few minutes later the deployment is completed.






Now we need to connect to the VM. On Azure portal page click on Virtual Machines then choose the new VM we just build. You can click on "download RDP file" or use your own RDP file. All we need are the machine's IP address and login name. Please use machine name\login name as the full login.



Upon connection we can confirm the VM specs. Surprisingly it's not Windows 2019 as claimed. It is still Win 2016 image.
















Friday, March 8, 2019

Series 9 - Build SSAS 2019 on a quad-node Windows 2019 cluster

In my previous series of failover clusters, I wrote about building SQL Server 2017 on Windows 2012/2016  Hyper-V virtual machines, with Windows iSCSI or StarWind virtual SAN as shared storage. It is the year of 2019 now and our cluster series need a face lift. With recent release of Windows Server 2019 and SQL Server 2019 CTP, I'm experimenting with these bleeding edge technologies and logging an update in the series. It is a single post with all-in-one contents since a large portion of it are duplicate of past posts. I'll try to avoid redundant steps but focus on new feature/interfaces or something worth an emphasis.

I'm using the same hardware as described in Series 1. Software includes Windows Server 2019 Datacenter Eval. and SQL Server 2019 CTP 2.3. Let's first lay down a chart that contains critical info for the environment we're building. In the following table, all nodes specs are listed for reference. 


Server  Name
P or V
Public NIC
Heartbeat NIC
iSCSI NIC
Purpose
Drives
HPV-HOST
HP
PL 360
IP: 192.168.1.123
For vEthernet
N/A
DC
C:\ 136 GB (OS)
SM: 255.255.255.0
DNS
D:\ 136 GB (Node 1)
DG: 192.168.1.1
Hyper-V host
E:\ 136 GB (Node 2)
DNS: 71.243.0.12
iSCSI target
F:\ 136 GB (Node 3)
DNS: 71.250.0.12

G:\256 GB (Node 4)
DNS: 192.168.1.123

    - USB
PARADISE
CLUSTER
DNS
192.168.1.136
N/A
N/A
Windows cluster name

PARADISE
SQLFCI
DNS
192.168.1.137
N/A
N/A
SQL Server FCI cluster name

MSDTC
DNS
192.168.1.138
N/A
N/A
Distributed Transaction

FCIVM01
Vm
IP: 192.168.1.144
IP: 10.10.10.44
IP: 8.8.8.4
SQL 2019
C:\ 40 GB
SM: 255.255.255.0
SM: 255.0.0.0
SM: 255.0.0.0
SSIS/SSRS
DG: 192.168.1.1
DG: N/A
DG: N/A
MDS/DQS
DNS: 192.168.1.123
DNS: N/A
DNS: N/A
SSAS
FCIVM02
Vm
IP: 192.168.1.145
IP: 10.10.10.45
IP: 8.8.8.5
SQL 2019
C:\ 50 GB
SM: 255.255.255.0
SM: 255.0.0.0
SM: 255.0.0.0
SSIS/SSRS
DG: 192.168.1.1
DG: N/A
DG: N/A
MDS/DQS
DNS: 192.168.1.123
DNS: N/A
DNS: N/A
SSAS
FCIVM03
Vm
IP: 192.168.1.146
IP: 10.10.10.46
IP: 8.8.8.6
SQL 2019
C:\ 50 GB
SM: 255.255.255.0
SM: 255.0.0.0
SM: 255.0.0.0
SSIS/SSRS
DG: 192.168.1.1
DG: N/A
DG: N/A
MDS/DQS
DNS: 192.168.1.123
DNS: N/A
DNS: N/A
SSAS
FCIVM04
Vm
IP: 192.168.1.147
IP: 10.10.10.47
IP: 8.8.8.7
SQL 2019
C:\ 50 GB
SM: 255.255.255.0
SM: 255.0.0.0
SM: 255.0.0.0
SSIS/SSRS
DG: 192.168.1.1
DG: N/A
DG: N/A
MDS/DQS
DNS: 192.168.1.123
DNS: N/A
DNS: N/A
SSAS


Part 1 - Hyper-V host and virtual machines


Download and install Windows 2019 with GUI. There's not much difference in the installation phase compared to Windows 2016 or 2012. Be sure to set up networking per the chart (top row). In Server Manager add roles and features: Domain controller, DNS server, Hyper-V and iSCSI target server. 



In Hyper-V Manager, the only thing to configure is virtual switch. Create three virtual switches for external, internal and private respectively. You can see in the following screenshot, my physical QLogic Gig bit ethernet card has been mapped to an external virtual switch. I also created a private Heartbeat virtual switch and an internal iSCSI virtual switch. Here is a summary of three types of virtual switches:

External - Allows host to talk to Internet as well as cluster nodes. A default gateway and subnet mask are must.
Internal - Allow talks among cluster nodes and between cluster nodes and Hyper-V host. No talk to Internet. Only a subnet mask is needed.
Private - Only allow talks among cluster nodes. No talks to host or to Internet. Only a subnet mask is needed.




For virtual machine setting, we also want to add three virtual NICs: public for application connection, private for heartbeat communication and iSCSI to talk to storage target server. Also make sure 2 CPUs, 4 GB of RAM and 40 GB of disk space is allocated for each vm. Then mount Windows 2019 ISO image to start installation. In Series 7 I wrote about how to use sysprep to clone a Hyper-V virtual machine. Here I'm going to follow suite to create four VMs as shown below, using FCIVM01 as template then cloning FCIVM02, FCIVM03, and FCIVM04


Part 2 - Configure iSCSI shared storageSince we have added iSCSI target on the host server now we can start creating virtual disks that nodes can share. The steps are pretty much the same as Windows 2017 described in Series 8. 

Part 3 - Install Windows 2019 failover cluster

Building Windows cluster was outlined as in Series 3, albeit we're using Windows 2019 instead of 2016, and running on four nodes instead of three. In order to get a all-green validation report which i prefer, we need to manually run Windows updates on all nodes to make sure they're consistent. This may require rebooting VMs a few times. It may also require to manually put shared offline disks online.


With cluster name and IP address it is pretty quick to set up a cluster. Once done we can create a fake role to test failover. Right click on Roles in FCM then choose "Create Empty Role". A new role is now added. You can right click on it to move to Best possible node or to a node of your choice. 


Part 4 - Install SQL/SSAS 2019 on Windows cluster 2019



On March 1st Microsoft released SQL Server 2019 CTP 2.3. Follow this link to download the 180-day trial: 
https://www.microsoft.com/en-us/evalcenter/evaluate-sql-server-2019-ctp The downloaded primer executable is about 4 MB. Double click it to launch a real window in which you can choose "Basic" to install SQL Server with default, "Custom" to review/change each detailed installation windows, or "Download media" to just download ISO or CAB file without installation.

We choose the last option to download the .iso image file (about 1.35 GB). On FCIVM01, mount the iso file to DVD drive. Click on setup.exe. When SQL Server Installation Center (SSIC) is opened, choose "New SQL Server failover cluster installation" on the right side. Accept license terms.Note the cluster verification step generated a warning. I strongly suggest revisiting the cluster validation report and fix underlying issues. If it's because of  a missing Windows Defender Antivirus definition update you probably can get away with it. Trivial inconsistency like this likely won't cause cluster installation to fail. So we ignore the warning and move on. On Feature Selection page, select all but Machine Learning Services, R, Python, and PolyBase. They tend to bug out causing installation failures. Keep in mind if SQL Server installation failed it will be nasty to clean up the mess. It will require uninstalling SQL server and/or probably destroying the whole cluster as SQL Service resource has been retained in it.Fill in SQL Server virtual network name (VNN).

We choose all cluster disks to install SQL Server. Note disk 4 is quorum so it's not available.


We have already created a DNS record for the VNN. Just type in its IP address. Notice the network was automatically detected and it matches our NIC assignment.


Based on least privilege principle we used dedicated AD user accounts for services. Notice startup types are Manual as it will be controlled by cluster service. 




Configure tempdb directories. Ignore the warning about large log file. 


In SSAS configuration choose Tabular Mode. Use default paths.


The last page is a summary before actual installation kicks off. 



Finally the installation finished. Check to see that SQL Server service now is under cluster role.

Now we need to install DBA tool SQL Server Management Studio 18.0 (preview 7) from the URL below:



Once SSMS is installed open a query windows and you can run at least five different T-SQL statements to retrieve the current cluster node info.


On FCIVM02, 03, 04 repeat installation of SQL Server by clicking on "Add node to a SQL Server failover cluster" in SSIC. Follow the installation steps detailed in Series 4. It's much quicker than installing the initial node. You just need to type in passwords for the service accounts. You can mount the ISO file on all nodes at the same time and do installations in parallel to save time. The end result - a SQL 2019 cluster is built with four nodes. The classic way of checking cluster is to use FCM (Failover Cluster Manager). 


In Windows 2019 a web GUI tool WAC (Windows Admin Center).has been introduced. The funny thing about it is only Google Chrome can open the URL. Microsoft IE or Edge is not supported. You can hit either URLs to access WAC - https://localhost or https://FCIVM01


You pretty much are able to do everything you normally do with FCM (except for creating cluster) in WAC. Plus it integrates other facets in Windows admin including Server Manager, Computer Manager, etc. In the following screenshots I demoed failover SQL Server service from node 4 to node 1.


I can also click on node 3 to delve into its detailed status and specs.


Part 5 - Build, deploy, maintain SSAS 2019 Tabular model on Windows cluster 2019


Now let's restore a copy for sample Data Warehouse backup from Github. Follow the link below to download AdventureWorksDW2017.bak:


To restore the backup, login in PARADISESQLFCI from SSMS and run database restore. Next we need to build a Tabular Model project using SQL Data Tools (SSDT). From the link below choose most recent release to download.


Launch SSDT-Setup-ENU.exe, check all options. Take default to proceed with installation.


Upon completion of SSDT installation, start the tutorial by creating a SSAS solution/project following the link down below:


The tutorial contains detailed tasks we're not covering here. When the Tabular model is built from SSDT we will deploy it to SSAS cluster. Alternatively you can download the sample Tabular model backup from Github and restore to SSAS server. Choose "adventure-works-tabular-model-1200-full-database-backup.zip" from here: 

https://github.com/Microsoft/sql-server-samples/releases/tag/adventureworks-analysis-services

There is a 5.5 MB backup file "Adventure Works Internet Sales Database.abf" inside the downloaded zip file. Unzip it and restore from Analysis server. You can do this through either SSMS GUI or XMLA script. 

Finally let's test querying Tabular model while performing a failover of the cluster. In SSMS open up an MDX query window, run the following command:

select 
{[DimProduct].[ModelName].[Model Name]} on columns,
{[DimProduct].[StartDate].[StartDate]} on rows
from [Adventure Works Internet Sales Model];

Move the SQL Server role to another node. Press F5 to run the same query. During seconds of connection interruption, the query may throw an error. But once the role failover completes and resource gets back online again, the query runs successfully and returns four rows of start dates.