Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a little problem. I can't get SQL Server Express installed within my application in windows 7 32 and 64 bit version.

It gets installed correctly in windows XP.

And it gets installed correctly in windows 7 32 bit or 64 bit if I run install from cmd.exe.

But if I try to run it with same parameters within my code it fails.

Bit of my code:

const string strNTAuthorityUser = "\"NT AUTHORITY\\NETWORK SERVICE\"";
var strBultInAddmins =  "\"BUILTIN\\ADMINISTRATORS\"";

var sqlParameters = string.Format(" /q  /IACCEPTSQLSERVERLICENSETERMS /ACTION=Install /INSTANCENAME={0} /SQLSYSADMINACCOUNTS={1}",
strDefaultDataSource, strBultInAddmins);
sqlParameters = string.Format("{0}  /FEATURES=SQLENGINE  /SQLSVCACCOUNT={1}  /SQLSVCSTARTUPTYPE=Automatic ", sqlParameters, strNTAuthorityUser);
sqlParameters = string.Format(" {0}  /TCPENABLED=1  /ENABLERANU=1  /NPENABLED=1 /SECURITYMODE=SQL /SAPWD={1}    ", sqlParameters, strPassword);

if (Is64BitSystem() && strMyOtherCustomParameter == "New")
{                 
   filename = filename +"SQLEXPRWT_x64_ENU.exe ";
}
else if (!Is64BitSystem() && strMyOtherCustomParameter == "New")
{
   filename = filename + "SQLEXPRWT_x86_ENU.exe ";
}
var setupProcess = new Process { StartInfo = { FileName = strFileName, Arguments = strParams, UseShellExecute = true, Verb = "runas" } };
//setupProcess.StartInfo.UseShellExecute = false; // to avoid a shell window 
try
{
   setupProcess.Start();
   Progress.Invoke(18);
}
catch (Exception ex)
{
   MessageBox.Show(ex.Message);
   var closeForms = new CloseAllForms();
   closeForms.CloseForm(strPath, strCode);
   closeForms.CloseApp(true);
   bInstaled = false;
}
// Monitor the process on 5-second intervals:
while (!setupProcess.WaitForExit(5000))
{
   try
   {
      if (longStart != 0)
      {
          int intTemp = (int)(GetFolderSize(dirRoot + dirPath) - longStart);
          Progress.Invoke(intTemp);
          longStart = longStart + intTemp;
      }
      else
      {
         if (Directory.Exists(dirRoot + dirPath))
         {
            longStart = GetFolderSize(dirRoot + dirPath);
            Progress.Invoke((int)longStart);
         }
      }
   }
   catch { }
}

Error:

Overall summary: Final result:
SQL Server installation failed. To continue, investigate the reason for the failure, correct the problem, uninstall SQL Server, and then rerun SQL Server Setup. Exit code (Decimal): -2068119551
Exit facility code: 1211
Exit error code: 1
Exit message: SQL Server installation failed. To continue, investigate the reason for the failure, correct the problem, uninstall SQL Server, and then rerun SQL Server Setup. Start time:
2011-03-01 17:29:27 End time:
2011-03-01 17:32:43 Requested action: Install

Machine Properties: Machine name:
LAB-WIN-7-32 Machine processor count: 2 OS version:
Windows 7 OS service pack:
Service Pack 1 OS region:
United States OS language:
English (United States) OS architecture: x86
Process architecture: 32 Bit OS clustered: No

Product features discovered: Product Instance Instance ID
Feature
Language Edition
Version Clustered

Package properties: Description:
SQL Server Database Services 2008 R2
ProductName: SQL Server 2008 R2 Type:
RTM Version:
10 SPLevel: 0 Installation location:
c:\acb30b784cdcbf067cbd714a9b\x86\setup\ Installation edition: EXPRESS

User Input Settings: ACTION:
Install ADDCURRENTUSERASSQLADMIN:
True AGTSVCACCOUNT:
NT AUTHORITY\NETWORK SERVICE
AGTSVCPASSWORD: *
AGTSVCSTARTUPTYPE:
Disabled ASBACKUPDIR:
Backup ASCOLLATION:
Latin1_General_CI_AS ASCONFIGDIR:
Config ASDATADIR:
Data ASDOMAINGROUP:
ASLOGDIR:
Log ASPROVIDERMSOLAP: 1 ASSVCACCOUNT: ASSVCPASSWORD: *
ASSVCSTARTUPTYPE:
Automatic ASSYSADMINACCOUNTS:
ASTEMPDIR:
Temp BROWSERSVCSTARTUPTYPE:
Automatic CONFIGURATIONFILE:
C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20110301_172836\ConfigurationFile.ini CUSOURCE:
ENABLERANU: True
ENU: True
ERRORREPORTING: False
FARMACCOUNT: FARMADMINPORT: 0
FARMPASSWORD:
FEATURES:
SQLENGINE FILESTREAMLEVEL:
0 FILESTREAMSHARENAME:
FTSVCACCOUNT:
FTSVCPASSWORD:
HELP: False IACCEPTSQLSERVERLICENSETERMS: True INDICATEPROGRESS:
False INSTALLSHAREDDIR:
C:\Program Files\Microsoft SQL Server\ INSTALLSHAREDWOWDIR:
C:\Program Files\Microsoft SQL Server\ INSTALLSQLDATADIR: INSTANCEDIR:
C:\Program Files\Microsoft SQL Server\ INSTANCEID:
SALINSTANCE INSTANCENAME:
SALINSTANCE ISSVCACCOUNT:
NT AUTHORITY\NetworkService
ISSVCPASSWORD:
ISSVCSTARTUPTYPE:
Automatic NPENABLED:
1 PASSPHRASE:
PCUSOURCE: PID: *
QUIET: True
QUIETSIMPLE: False
ROLE:
AllFeatures_WithDefaults
RSINSTALLMODE:
FilesOnlyMode RSSVCACCOUNT:
NT AUTHORITY\NETWORK SERVICE
RSSVCPASSWORD:
RSSVCSTARTUPTYPE:
Automatic SAPWD:
SECURITYMODE: SQL SQLBACKUPDIR:
SQLCOLLATION:
SQL_Latin1_General_CP1_CI_AS
SQLSVCACCOUNT: NT AUTHORITY\NETWORK SERVICE
SQLSVCPASSWORD: *
SQLSVCSTARTUPTYPE:
Automatic SQLSYSADMINACCOUNTS:
BUILTIN\ADMINISTRATORS SQLTEMPDBDIR: SQLTEMPDBLOGDIR:
SQLUSERDBDIR:
SQLUSERDBLOGDIR:
SQMREPORTING:
False TCPENABLED:
1 UIMODE:
AutoAdvance X86:
False

Configuration file:
C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20110301_172836\ConfigurationFile.ini

Detailed results: Feature:
Database Engine Services Status:
Failed: see logs for details MSI status: Passed
Configuration status: Passed

Rules with failures:

Global rules:

Scenario specific rules:

Rules report file:
C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20110301_172836\SystemConfigurationCheck_Report.htm

Thanks

share|improve this question

migrated from stackoverflow.com Mar 2 '11 at 20:30

This question came from our site for professional and enthusiast programmers.

    
I think you should start your program with administrative privileges under win7. –  acoolaum Mar 2 '11 at 18:03

2 Answers 2

Here is a class I've used recently.

public static class MSSQL2008CommandlineInstaller
  {
    const string MSSQL_SERVER_VERSION = "SQLSERVER2008";
    const string MSSQL_INSTALLER_APP = "SQLEXPR_x86_ENU.exe";

    public static int Install(string saPassword, string instanceName)
    {
      string configFileName = Directory.GetCurrentDirectory() + "\\MSSQLInstallationConfig.ini";

      CreateMsSQLConfigurationFile(configFileName, instanceName);
      return StartInstallation(MSSQL_INSTALLER_APP, saPassword, configFileName);
    }

    private static int StartInstallation(string installerApplication, string saPassword, string configFileName)
    {
      using (var process = new Process())
      {
        process.StartInfo = new ProcessStartInfo(installerApplication);
        process.StartInfo.Arguments = "/SAPWD=\"" + saPassword + "\" /CONFIGURATIONFILE=\"" + configFileName + "\"";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardError = true;
        process.OutputDataReceived += new DataReceivedEventHandler(OnOutputDataReceived);
        process.ErrorDataReceived += new DataReceivedEventHandler(OnErrorDataReceived);
        process.StartInfo.CreateNoWindow = true;
        process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        process.Start();
        process.BeginOutputReadLine();
        process.BeginErrorReadLine();
        process.WaitForExit();
        int exitCode = process.ExitCode;
        process.Close();
        return exitCode;
      }      
    }

    public static void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
    {
      if (!String.IsNullOrEmpty(e.Data))
        Console.WriteLine("Output: " + e.Data);
    }

    public static void OnErrorDataReceived(object sender, DataReceivedEventArgs e)
    {
      if (!String.IsNullOrEmpty(e.Data))
        Console.WriteLine("Error: " + e.Data);
    }

    private static void CreateMsSQLConfigurationFile(string fileName, string instanceName)
    {
      using (var configFile = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
      {
        StreamWriter writer = new StreamWriter(configFile);
        writer.WriteLine("[" + MSSQL_SERVER_VERSION + "]");
        writer.WriteLine("IACCEPTSQLSERVERLICENSETERMS=\"True\"");
        writer.WriteLine("INSTANCEID=\"" + instanceName + "\"");
        writer.WriteLine("INSTANCENAME=\"" + instanceName + "\"");
        writer.WriteLine("ACTION=\"Install\"");
        writer.WriteLine("FEATURES=SQLENGINE");
        writer.WriteLine("HIDECONSOLE=\"True\"");
        writer.WriteLine("QUIET=\"True\"");
        writer.WriteLine("QUIETSIMPLE=\"False\"");
        writer.WriteLine("HELP=\"False\"");
        writer.WriteLine("INDICATEPROGRESS=\"False\"");
        writer.WriteLine("X86=\"False\"");
        writer.WriteLine("ROLE=\"AllFeatures_WithDefaults\"");
        writer.WriteLine("ENU=\"True\"");
        writer.WriteLine("ERRORREPORTING=\"False\"");
        writer.WriteLine("SQMREPORTING=\"False\"");
        writer.WriteLine("AGTSVCACCOUNT=\"NT AUTHORITY\\NETWORK SERVICE\"");
        writer.WriteLine("AGTSVCSTARTUPTYPE=\"Automatic\"");
        writer.WriteLine("SQLSVCACCOUNT=\"NT AUTHORITY\\NETWORK SERVICE\"");
        writer.WriteLine("SQLSVCSTARTUPTYPE=\"Automatic\"");
        writer.WriteLine("SECURITYMODE=\"SQL\"");
        writer.WriteLine("ADDCURRENTUSERASSQLADMIN=\"True\"");
        writer.WriteLine("FILESTREAMLEVEL=\"0\"");
        writer.WriteLine("ENABLERANU=\"True\"");
        writer.WriteLine("SQLCOLLATION=\"SQL_Latin1_General_CP1_CI_AS\"");
        writer.WriteLine("TCPENABLED=\"1\"");
        writer.WriteLine("NPENABLED=\"1\"");
        writer.WriteLine("BROWSERSVCSTARTUPTYPE=\"Automatic\"");

        writer.Flush();
      }
    }
  }

You may need to change some commandline options to suit your need obviously. Essentially, what it does is it creates a confguration.ini file and then when it starts the installer process is provides that file as the path.

some parameters are excluded because they can't be provided in the INI file. Those parameters (such as sa password etc.) are part of the command line when starting the installer process. you can also add some aaditional parameters to the ini file or command line.

Example command line aruguments:

/Q /HIDECONSOLE="True" /CONFIGURATIONFILE="FullPathToConfiguration.ini" 
share|improve this answer

After scrutinising my Config.ini file, I noticed that I had a parameter called SQLSYSADMINACCOUNTS filled in with the machine name and user name that I used to generate the ini file initially.

Commented out the parameter and now my installer works on the machine it has been failing on for 2 days.

UPDATE: Commenting out the parameter made the installer work, but I could not access the server, the current user was not set as an admin, even though that parameter was set as true in the ini file. Am now testing with the parameter blanked out but present.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.