How to check if a client has SQLNCLI10 provider installed when browsing?
I have a c# website that allows a client to connect directly to a remote SQL Server database from their PC, bypassing the web server, by using a 3rd party ActiveX control. I was originally using the SQLOLEDB provider and it was working fine. The clients are in an internal network (using Windows machines and Internet Explorer) and the website is not intended for exposure to the general internet.
I had to upgrade from using the SQLOLEDB provider to the SQLNCLI10 provider to cater for the new datatypes in SQL Server 2008. It worked on my PC, but broke in production. What I didn't realise is that it worked because the SQLOLEDB provider is part of the Windows OS (MDAC/WDAC) so already exists on the client's PC. The SQLNCLI10 provider is included as part of SQL Server 2008 and has to be installed separately on the client machine (because most of them won't have SQL Server installed, but I do).
I can开发者_Python百科 provide a link for them to download a standalone Microsoft SQL Server 2008 Native Client provider from, but how do I check if they already have it installed?
Frustratingly, Microsoft does not seem to give an unambiguous answer on how to test whether the client library is present. Web searching and registry sniffing reveals at least the follow registry keys:
HLKM\SOFTWARE\Microsoft\SQLNCLI11 (key:InstalledVersion)
HLKM\SOFTWARE\Microsoft\SQLNCLI10 (key:InstalledVersion)
HKLM\SOFTWARE\Microsoft\Microsoft SQL Native Client\CurrentVersion (version 9, i presume?)
HLKM\SOFTWARE\Microsoft\Microsoft SQL Server Native Client 10.0\CurrentVersion (key:Version)
HLKM\SOFTWARE\Microsoft\Microsoft SQL Server Native Client 11.0\CurrentVersion (key:Version)
This blog post at MSDN suggests that using registry keys to answer a related question (is SQL Server Express installed) is wrong, wrong, wrong and you should write 200 lines of WMI code instead. The WMI approaches seem equally undocumented and even more fragile to me.
Since Microsoft allows the SQL Native Client package to be redistributed, perhaps the best choice is simply include the msi in your application's installer and run it whether it is needed or not. See this list of supported operating system for the various drivers they provide which reveals there is also a version 10.5(!).
SQLNCLI is installed in parallel to MDAC-based drivers, so it should be safe to run msiexec
on this and let it take care of the details.
Simply, check registry keys or files
- Registry:
HKLM\SOFTWARE\Microsoft\Sqlncli10
- File: Check for sqlncli10.dll in \System32
Or you can use WMI too
It could be HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\SQLNCLI10\CurrentVersion
too where you can compare version eg 10.0.1600.22 as per your link
精彩评论