Showing posts with label snac. Show all posts
Showing posts with label snac. Show all posts

2015-11-05

SQL Server Native Client WMI name

I am developing a SQL Server deployment package. And again I do not hit the nail in the first stroke.
This makes me install - and uninstall - SQL Server components several times. Rather quickly I get tired by clicking through Uninstall in Windows Control Panel. This can usually be fixed with a PowerShell script, but uninstalling SQL Server Native Client (SNAC) gave me some trouble.

To get the metadata on the installed programs through CIM I created a variable to work on
$CimProduct = Get-CimInstance -ClassName Win32_Product -Filter "Name LIKE 'Microsoft SQL Server 2012 Native Client'"
But the result in $CimProduct was empty.

A general request showed me that SNAC is installed with the name that I filtered on
Get-CimInstance -ClassName Win32_Product -CimSession $CimSession
gave a long list which I have narrowed down here
Name             Caption                                              Vendor                                               Version
----             -------                                              ------                                               -------
...
Microsoft SQL... Microsoft SQL Server 2012 Native Client              Microsoft Corporation                                11.0.2100.60
...

Then I tried a more general filter
$CimProduct = Get-CimInstance -ClassName Win32_Product -Filter "Name LIKE '%Native Client%'"
"Name = '$($CimProduct.Name)'."

with success
Name = 'Microsoft SQL Server 2012 Native Client '.
Immediately it looked like the text that I filtered on in the beginning.
But notice the trailing space!
If I some day meet the Product Manager we have something to talk about ;-)

With the new knowledge I got the search right
$CimProduct = Get-CimInstance -ClassName Win32_Product -Filter "Name LIKE 'Microsoft SQL Server 2012 Native Client '"

Now I was able to uninstall SNAC in one line
$Uninstall = Invoke-CimMethod -Query "SELECT * FROM Win32_Product WHERE Name = 'Microsoft SQL Server 2012 Native Client '" -MethodName Uninstall
$Uninstall.ReturnValue

And with success
0

2009-03-10

SQL Server Native Client (SNAC)

SNAC is not documentet in Books Online (BOL), but in the learning section of MSDN:
Data Platform Developer Center > Learn > Microsoft SQL Server Native Client

Also there is a blog about SNAC. The reference to the blog is at the page referenced above.

The installed version can be found in the Registry:
HKLM\SOFTWARE\Microsoft SQL Native Client\CurrentVersion\Version : [REG_SZ]
or
HKLM\SOFTWARE\Microsoft\SNAC\InstalledVersion : [REG_SZ]
Using PowerShell the value can be accessed like this
PS > $SnacVersion = get-itemproperty 'hklm:\software\microsoft\microsoft sql native client\currentversion' 'Version'
PS > $SnacVersion.Version
and the result could be
9.00.4035.00
The SNAC version for SQL Server 2008 can be found in the Registry at
HKLM\SOFTWARE\Microsoft\Microsoft SQL Server Native Client 10.0\CurrentVersion\Version : [REG_SZ]

To get the SNAC version on a remote host, I have used WMI and the StdReg provider:
function Get-SnacVersion {
Param( [string]$ServerName = '.' ) # Default local host
 $Reg = [WMIClass]"\\$ServerName\root\default:StdRegProv" # Remote host
 $HKLM = 2147483650
 $RegBranch = 'software\microsoft\microsoft sql native client\currentversion'
 $RegItem = 'Version'
 $Reg.GetStringValue($HKLM, $RegBranch, $RegItem).sValue
}

The function is called like this for the local host:
Get-SnacVersion
Getting the SNAC version on a remote host the function is called like this:
Get-SnacVersion 'Sandbox.sqladmin.dk'
The result is equal the result above from the Registry.

The existance of SNAC can be determined by either the existance of the Registry braches above or if the file "sqlncli.dll" exists in the folder "%SYSTEM%" (e.i. "C:\WINDOWS\system32\").
The SQL Server 2008 SNAC is implemented in the file "sqlncli10.dll".

Installation of SNAC itself can be done with the Feature Pack for Microsoft SQL Server.
A reference to this can be found at the page referenced in the beginning of this entry.

Why Microsoft (again) has a seperate installation and path for SQL Server 2008 I don't know. I'm not impressed as is will only make automated maintenance much more complex.

The book "Windows PowerSehll: TFM" (2nd Edition) har a whole chapter on managing the Registry with PowerShell (chapter 30).