简体   繁体   中英

Determine if SqlLocalDB is installed

I am searching for a way to determine in WiX if SQLLocalDB is installed or not. How can I do this? - Can I check a registry-key? - When yes, which key?

A RegistrySearch should do it:

<Property Id="LOCALDB">
   <RegistrySearch Id="SearchForLocalDB" Root="HKLM" 
                   Key="SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11E.LOCALDB\MSSQLServer\CurrentVersion"
                   Name="CurrentVersion"
                   Type="raw" />
</Property>

That would get you the version.

Checking from the registry may not work all the time becasue if user uninstall the localDb then registry entries may still exist.

Here is the function I am using to identify the localDB installation from command line -

    internal static bool IsLocalDBInstalled()
    {
        // Start the child process.
        Process p = new Process();
        // Redirect the output stream of the child process.
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.FileName = "cmd.exe";
        p.StartInfo.Arguments = "/C sqllocaldb info";
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        p.Start();
        // Do not wait for the child process to exit before
        // reading to the end of its redirected stream.
        // p.WaitForExit();
        // Read the output stream first and then wait.
        string sOutput = p.StandardOutput.ReadToEnd();
        p.WaitForExit();

        //If LocalDb is not installed then it will return that 'sqllocaldb' is not recognized as an internal or external command operable program or batch file.
        if (sOutput == null || sOutput.Trim().Length == 0 || sOutput.Contains("not recognized"))
            return false;
        if (sOutput.ToLower().Contains("mssqllocaldb")) //This is a defualt instance in local DB
            return true;
        return false;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM