What is the best way to detect the presence of SMO?

I have code that uses SMO to populate a list of available SQL servers and databases. Although we no longer support SQL Server 2000, it is possible that the code may be running on a computer that SQL Server 2000 does not have an SMO library. I would ask first to check SMO and degrade functionality, and not to explode the face of the user. What is the best way to determine if SMO is available on a machine?

Each example that I saw during a quick Google crawl was an option to "look for C: \ Program Files \ Microsoft SQL Server \ 90 \ SDK \ Assemblies \ Microsoft.SqlServer.Smo.dll". The problem with this approach is that it only works with SQL Server 2005. If SQL Server 2008 is the only SQL Server installed, the path will be different.

+5
source share
5 answers

I looked at SharedManagementObjects.msi from the SQL2008 R2 feature package, and my Windows registry (SQL2008 R2 Dev is installed on this computer), and I believe that these are the registry keys that should be used to detect SMO (all under HKLM):

\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion - , -, , , ​​ SMO.

\Microsoft\Microsoft SQL Server 2008 Redist\SharedManagementObjects\1033\CurrentVersion - , , 2008 . , SOFTWARE\Microsoft\Microsoft SQL Server 2008 Redist\SharedManagementObjects.

SQL2012: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server 2012 Redist\SharedManagementObjects\1033\CurrentVersion

SQL2005! , 2005 .

: CLR Microsoft SQL Server System, SMO . SQLSysClrTypes.msi : \Microsoft\Microsoft SQL Server\RefCount\SQLSysClrTypes

+6

, , , . HKEY_CLASSES_ROOT SMO-. , , SMO . true, SMO ​​, false, .

private bool CheckForSmo()
{
    string RegKeyName = @"Microsoft.SqlServer.Management.Smo.Database";
    bool result = false;
    Microsoft.Win32.RegistryKey hkcr = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(RegKeyName);
    result = hkcr != null;

    if (hkcr != null)
    {
        hkcr.Close();
    }

    return result;
}
+3

SMO. , .

+3

SQL Server 2012:

HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion\Version

, ( , 11).

+1

: HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion\Version , , .

, , SMO ​​2014, 12.x, SMO 2012, 11.x 2014, 12.x

: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server 2012 Redist\SharedManagementObjects\1033\CurrentVersion

or HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SQL Server 2014 Redist \ SharedManagementObjects \ 1033 \ CurrentVersion

Does anyone know if 1033 is guaranteed? (Meaning only English version)

0
source

All Articles