Search code examples
sql-servervisual-studio-2017windows-installersql-server-expressburn

SQL Server named instance with Visual Studio 2017 Installer project


Software:

  1. SQL Server Express 2016
  2. Visual Studio 2017

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

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

  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

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

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.

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

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

Solution

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

    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.