带有 Visual Studio 2017 安装程序项目的 SQL Server 命名实例 [英] SQL Server named instance with Visual Studio 2017 Installer project

查看:30
本文介绍了带有 Visual Studio 2017 安装程序项目的 SQL Server 命名实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

软件:

  1. SQL Server Express 2016
  2. Visual Studio 2017

我们一直在尝试将 SQL Server Express 2016 的命名实例安装为 VS 安装程序安装项目的一部分,但没有成功.

We've been trying without success to get a named instance of SQL Server Express 2016 installed as part of VS Installer Setup Project.

我们已经尝试按如下方式调用 InstallNamedInstance() 并得到给定的结果:

We've tried calling InstallNamedInstance() as follows with given results:

  1. 从管理员 cmd 窗口使用相同的命令行参数运行 SQLEXPR_x64_ENU.exe:成功
  2. 从控制台应用程序调用 InstallNamedInstance() 并从管理员 cmd 窗口运行控制台应用程序:成功
  3. 安装自定义操作(所有人和我自己):失败
  4. BeforeInstall 事件(所有人和我自己):失败
  1. Run SQLEXPR_x64_ENU.exe with same commandline args from Administrator cmd window: Succeeds
  2. Call InstallNamedInstance() from a Console app and run Console app from Administrator cmd window: Succeeds
  3. Install custom action (Both Everyone and Just Me): Fails
  4. BeforeInstall event (Both Everyone and Just Me): Fails

我注意到 msi 运行时的当前用户是 NT AUTHORITY\SYSTEM.每当安装程序项目失败时,它都会失败并显示以下消息:

I notice that current user when msi runs is NT AUTHORITY\SYSTEM. Whenever it fails from Installer project, it fails with below message:

运行 SQL Server 安装程序的帐户没有一个或所有以下权利:备份文件和目录的权利,管理审计和安全日志的权利以及调试程序.要继续,请使用具有这两项权利的帐户.有关更多信息,请参阅http://msdn.microsoft.com/en-us/library/ms813696.aspx,http://msdn.microsoft.com/en-us/library/ms813959.aspxhttp://msdn.microsoft.com/en-us/library/ms813847.aspx.

The account that is running SQL Server Setup does not have one or all of the following rights: the right to back up files and directories, the right to manage auditing and the security log and the right to debug programs. To continue, use an account with both of these rights. For more information, see http://msdn.microsoft.com/en-us/library/ms813696.aspx, http://msdn.microsoft.com/en-us/library/ms813959.aspx and http://msdn.microsoft.com/en-us/library/ms813847.aspx.

这是安装程序的限制还是我遗漏了什么?使用 AdvancedInstaller 会更好吗?

Is this a limitation of Installer project or am I missing something? Will we have better luck with AdvancedInstaller?

请注意,安装程序项目的先决条件对我们不起作用,因为我们必须创建 SQL Server Express 的命名实例,而且我们无法看到如何将命令行参数传递给先决条件.

Note that Installer Project's pre-requisite is not working for us because we're having to create a named instance of SQL Server Express and we're not able to see how we can pass commandline arguments to pre-requisite.

private void InstallNamedInstance()
{
    // NOTE: Change below instance name to get unique instances (or uninstall previous instance)
    var InstanceName = "TFPICDATABASES2";
    var proc = new Process();
    // NOTE:
    //  1. Download "SQLServer2016-SSEI-Expr.exe" web installer from https://www.microsoft.com/en-us/download/details.aspx?id=54284
    //  2. Run the web installer and choose 3rd option "Download Media". This will give "SQLEXPR_x64_ENU.exe"
    proc.StartInfo.FileName = @"c:\temp\sql\SQLEXPR_x64_ENU.exe ";
    proc.StartInfo.Arguments = " /Action=Install";
    proc.StartInfo.Arguments += $" /INSTANCEID={InstanceName}";
    proc.StartInfo.Arguments += $" /InstanceName={InstanceName}";
    proc.StartInfo.Arguments += " /ROLE=AllFeatures_WithDefaults";
    proc.StartInfo.Arguments += " /QS";
    proc.StartInfo.Arguments += " /INDICATEPROGRESS=True";
    proc.StartInfo.Arguments += " /IAcceptSQLServerLicenseTerms=True";
    proc.StartInfo.WorkingDirectory = @"c:\temp\sql";

    WriteLog($"FielName: {proc.StartInfo.FileName}; Arguments: {proc.StartInfo.Arguments}; WorkingDir: {proc.StartInfo.WorkingDirectory}");

    proc.StartInfo.UseShellExecute = false;
    proc.OutputDataReceived += (s, e) => WriteLog($"Info: {e.Data}");
    proc.ErrorDataReceived += (s, e) => WriteLog($"Error: {e.Data}");

    var ok = proc.Start();
    // NOTE: Log files are in C:\Program Files\Microsoft SQL Server\130\Setup Bootstrap\Log
    // Summary.txt gives log of latest installer run. It also creates one folder for each installer attempt
    // and gathers more detailed logs in those folders.
    proc.WaitForExit();
    WriteLog($"{proc.StartInfo.FileName} exited with {proc.ExitCode}");
    if (proc.ExitCode != 0)
    {
        throw new Exception($"SQL Server Express installation failed. Check log file for more details");
    }
}

推荐答案

我怀疑您在 SYSTEM 帐户下的自定义操作由于这些文章中提到的错误而失败:

I suspect your custom action fails under the SYSTEM account because of the errors mentioned in these articles:

在高级安装程序中,安装 SQL Server 的自定义操作不在系统帐户下运行,它在启动安装的帐户下运行(必须具有管理员凭据).自定义操作(Advanced Installer 捆绑的专用 exe 启动器)配置为需要管理员提升(我怀疑您无法在 VS 中配置),因此 SQL 的安装过程服务器正在使用机器上的普通用户帐户提升运行,而不是 NT SYSTEM.

In Advanced Installer, the custom action that installs SQL server does not run under the system account, it runs under the account that started the installation (which must have admin credentials). The custom action (a dedicated exe launcher bundled by Advanced Installer) is configured to require admin elevation (which I suspect you cannot configure in VS), therefore the install process for SQL server is running elevated using a regular user account from the machine, not NT SYSTEM.

这篇关于带有 Visual Studio 2017 安装程序项目的 SQL Server 命名实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆