Sunday, September 16, 2018

Completely Uninstall SQL Server 2016

Recently, I upgraded the development SQL database server on my workstation from SQL Server 2016 to SQL Server 2017.

After the upgrade, I tried to uninstall SQL Server 2016 from Windows Control Panel. But after the uninstall, there were still a lot of SQL Server 2016 components on my workstation. In fact, of the several SQL Server components shown in the Windows Control Panel, many would either not go away after uninstall, or would display dependency warnings and refuse to uninstall. In addition, there were many SQL Server 2016 components that were simply not shown in the Windows Control Panel.

So, I had to manually uninstall these components forcefully. First I ran a query for installed SQL Server 2016 components on the command line:

          wmic product where "name Like '%SQL%' and name like '%2016%'" get identifyingnumber,name,vendor,version > c:\temp\SQL2016Components.txt

Here the output file path "c:\temp\SQL2016Components.txt" is specific to my workstation, of course. You would need to change that to a path that is valid to your computer, obviously.

This command can take quite some to run.

After this command was completed, the contents of the output file would look like this:

IdentifyingNumber                       Name                                                                   Vendor                 Version       
{29A56A10-FEB1-4B4F-99DA-8DE4108AA1D8}  SQL Server 2016 Management Studio for Reporting Services Localization  Microsoft Corporation  13.0.16106.4  
{60B9E230-65C3-4A54-9659-1313FBC051B3}  Microsoft AS OLE DB Provider for SQL Server 2016                       Microsoft Corporation  13.0.2164.0   
{DD9B76B0-4B93-4C50-9A9E-4D1C7C3B596F}  SQL Server 2016 Management Studio                                      Microsoft Corporation  13.0.16106.4  
{8A3AE1F0-0752-435D-A01C-033BDD629C8B}  SQL Server 2016 Connection Info                                        Microsoft Corporation  13.0.14500.10 
{B9EED901-157A-4AB8-BFD1-2C6FBF5CF802}  SQL Server 2016 Common Files                                           Microsoft Corporation  13.0.1601.5   
{F8001E21-CFCC-47AD-A3B1-6B3EB6D35E48}  SQL Server 2016 Shared Management Objects                              Microsoft Corporation  13.0.14500.10 
{D3FC7A31-F127-4E2A-96F6-B24FA7D3FFAF}  SQL Server 2016 Shared Management Objects                              Microsoft Corporation  13.0.14500.10 
{1D792861-C84B-4BD0-8347-34AF40F5ACD1}  SQL Server 2016 Management Studio Extensions                           Microsoft Corporation  13.0.1601.5   
{EC234B43-728E-4CA9-8AE6-7815325D6AAD}  SQL Server 2016 Client Tools Extensions                                Microsoft Corporation  13.0.1601.5   
{59200093-D6A8-453E-B1AA-8D5E8921598A}  Microsoft SQL Server 2016 Setup (English)                              Microsoft Corporation  13.0.1601.5
   
...

From the contents of this file, I then created a batch file that looks like this:

msiexec /i {29A56A10-FEB1-4B4F-99DA-8DE4108AA1D8}
msiexec /i {60B9E230-65C3-4A54-9659-1313FBC051B3}
msiexec /i {8A3AE1F0-0752-435D-A01C-033BDD629C8B}
...

For each GUID in the output file of "wmic", I added a line "msiexec /i ..." with that GUID as the uninstall parameter.

Then I ran this batch file from the command line. 

I was getting prompted on each line of the batch file:


 

I selected "Yes" each time. On some steps, I was getting error popups:


On some other steps, I was getting warning popups like this:


But I continued with the batch file.

I repeated the batch file three times. On the third pass, none of the components remained. SQL Server 2016 was completely uninstalled.

To make sure that the new SQL Server 2017 installation has all the components intact, I ran SQL Server 2017 Setup, checked all of the features that I wanted. The SQL Server 2017 Setup has some problems (http://programount.blogspot.com/2018/06/sql-server-2017-installation-errors-on.html), but once patched, everything works fine.