hiren soni
hiren soni

Reputation: 174

Command line for SQL Server installation

I am trying to make a setup project which installs an SQL instance with password. My requirement is I want full installation in silent mode except Instance name. Is there any way I can supply any command in my command line that will allow the user to put his own Instance name? I tried /qn, /qb for 2005 and /qs for 2008 but they display all the dialog box.

Thanks in advance.

Upvotes: 0

Views: 2522

Answers (1)

The parameter to install without the SQL Server install window is /Q instead of /QS. See Microsoft's documentation here.

To supply an instance name, you need the /INSTANCENAME parameter. Here is an example of how to install SQL Server via command prompt without a SQL Server window:

SETUP.exe /Q /IACCEPTSQLSERVERLICENSETERMS /ACTION=install /FEATURES=SQL /INSTANCENAME=YourInstanceNameHere /SECURITYMODE=SQL /SAPWD="SQL Admin Password Here" /SQLSYSADMINACCOUNTS=""NT Authority\System"" /ADDCURRENTUSERASSQLADMIN=False

SETUP.exe = SQL Server install file

/Q = quiet install

/IACCEPTSQLSERVERLICENSETERMS = Required for quiet install

/ACTION = tells installer to install SQL

/FEATURES = tells installer which features to install

/INSTANCENAME = the name you want your SQL Server instance to be

/SECURITYMODE = tells SQL to use SQL Server Authentication instead of Windows Auth

/SAPWD = creates the password for the SQL Server Login

/SQLSYSADMINACCOUNTS = installs SQL with specified admin user

/ADDCURRENTUSERASSQLADMIN = self explanatory

Here is a C# example to run the process from an application, note: like Command Prompt, your application will need to run as an administrator:

        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
        startInfo.CreateNoWindow = true;
        startInfo.UseShellExecute = false;
        startInfo.RedirectStandardError = true;
        startInfo.RedirectStandardOutput = true;
        startInfo.FileName = "path to SETUP.exe file";
        startInfo.Arguments = "the above mentioned arguments";

        System.Diagnostics.Process processObj = new System.Diagnostics.Process();
        processObj.StartInfo = startInfo;
        processObj.Start();                

        do
        {
            //refresh the process
            processObj.Refresh();

        } while (!processObj.WaitForExit(1000));

Tested on SQL Server 2019 and Visual Studio 2013.

Upvotes: 1

Related Questions