【问题标题】:Determine if SqlLocalDB is installed判断是否安装了SqlLocalDB
【发布时间】:2013-03-18 20:43:16
【问题描述】:

我正在寻找一种在 WiX 中确定是否安装了 SQLLocalDB 的方法。我怎样才能做到这一点? - 我可以检查注册表项吗? - 如果是,哪个键?

【问题讨论】:

  • 就个人而言,我更喜欢测试与数据库实例的连接性,而不是将自己耦合到特定的实例/版本。
  • @christopherpainter - 我如何在 WiX 中执行此操作来决定是否安装 LocalDB?
  • 我认为可以使用自定义引导程序 UI 为用户提供安装 LocalDB 或提供替代连接详细信息以供验证的选择。这是一个广泛的问题,需要详细设计而不是简单的答案。

标签: wix localdb wix3.7


【解决方案1】:

RegistrySearch 应该这样做:

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

这会给你版本。

【讨论】:

【解决方案2】:

从注册表检查可能不会一直有效,因为如果用户卸载 localDb,那么注册表项可能仍然存在。

这是我用来从命令行识别 localDB 安装的函数 -

    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;
    }

【讨论】:

    猜你喜欢
    • 2012-07-09
    • 1970-01-01
    • 2013-10-26
    • 1970-01-01
    • 2010-09-16
    • 2012-06-25
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多