SQL2012 LocalDB: how to check in c# if it is currently installed?
Asked Answered
R

4

22

How to check in c# code if LocalDB currently installed? also, how to check if SQLNCLI11 presents in system?

Richie answered 24/7, 2012 at 9:51 Comment(0)
A
3

I found this nuget package that wraps up working with SQLLocalDB Has the following command

SqlLocalDbApi.IsLocalDBInstalled()
Affectionate answered 25/5, 2018 at 14:18 Comment(0)
R
15

Check if LocalDB is installed, by looking for this registry key:

[HKLM\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\11.0]

SQLNCLI11 - check the file version and presence of this file: C:\WINDOWS\system32\sqlncli.dll

Rotogravure answered 24/7, 2012 at 10:35 Comment(4)
I have a little confusion. Need to know a little something to clear. In MS Visual Studio 2010, I can create database and work with it. (probably MS SQL Server express, which is by default integrated with VS 2010). Is it what we're refering as LocalDB?Architectonic
No, not exactly the same, but similar productsRotogravure
This won't work if the user uninstalls localdb. The key is not removed.Undry
You might try HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11E.LOCALDB\SetupUndry
A
3

Here is a VB.NET example checking for LOCALDB

Public Shared Function CheckLocalDBExists() As Boolean
    Dim s As String = ""
    Dim reg As RegistryKey
    Dim rtn As Boolean = False
    reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\12.0", True)
    Try
        s = reg.GetValue("ParentInstance", "").ToString
        reg.Close()
    Catch ex As Exception
        s = Nothing
    End Try
    'MessageBox.Show(s)
    If s = "MSSQL12E.LOCALDB" Then
        rtn = True
    End If
    Return rtn
End Function
Acaroid answered 23/2, 2016 at 21:50 Comment(1)
Note: This test is for localdb 2014. For 2012 you need to check for installed version 11.0 and MSSQL11E.LOCALDB. (sorry for any confusion)Acaroid
A
3

I found this nuget package that wraps up working with SQLLocalDB Has the following command

SqlLocalDbApi.IsLocalDBInstalled()
Affectionate answered 25/5, 2018 at 14:18 Comment(0)
S
2

I'm using the answer to this question to check for the existence of sqllocaldb.exe

Like so:

public static bool IsLocalDBInstalled()
{
    return ExistsOnPath("SqlLocalDB.exe"); ;
}

public static bool ExistsOnPath(string fileName)
{
    return GetFullPath(fileName) != null;
}

public static string GetFullPath(string fileName)
{
    if (File.Exists(fileName))
        return Path.GetFullPath(fileName);

    var values = Environment.GetEnvironmentVariable("PATH");
    foreach (var path in values.Split(';'))
    {
        var fullPath = Path.Combine(path, fileName);
        if (File.Exists(fullPath))
            return fullPath;
    }
    return null;
}
Schutt answered 5/10, 2016 at 21:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.