Rama
Rama

Reputation: 65

Install SQL Server Silently Using C# Forms Application

I have an windows application developed in C#, I need to install it on a PC which will just have the Operating System and .Net Framework installed. Now I have to give an option to install SQL Server 2008 R2 Express edition on that PC, using this windows application. I have coded for installing/uninstalling a windows service, but struck with sql server installation. could someone help me out in doing this.

Upvotes: 4

Views: 12081

Answers (3)

Remus Rusanu
Remus Rusanu

Reputation: 294277

Follow the guidelines in How to Embed SQL Server Express in an Application. It covers everything you need, including pickiing up the right distribution, choosing an appropriate installation method (wpi vs. setup.exe) and how to configure the installation. the wiki even has a C# code on how to detect a previous Express instalation, how to invoke the WPI (Web Platform Installer) for SQL Express from C#:

System.Diagnostics.Process.Start(
  @"C:\Program Files\Microsoft\Web Platform Installer\webplatforminstaller.exe",
  " /id SQLExpress");

or using the "wpi://" URL handler:

System.Diagnostics.Process.Start("wpi://SQLExpress/");

or using the Web App Galery:

System.Diagnostics.Process.Start(
  "http://www.microsoft.com/web/gallery/install.aspx?appsxml=&appid=SQLExpress");

and, finally, using the SQL Express setup (recommended for advanced configuration):

System.Diagnostics.Process processObj = 
  System.Diagnostics.Process.Start(@"c:\temp\sqlsetup\setup.exe",

@"/q /Action=Install /Hideconsole /IAcceptSQLServerLicenseTerms=True 
 /Features=SQL,Tools /InstanceName=SQLExpress
 /SQLSYSADMINACCOUNTS=""Builtin\Administrators"" 
 /SQLSVCACCOUNT=""DomainName\UserName"" /SQLSVCPASSWORD=""StrongPassword""");

and it has the full list of setup parameters.

Upvotes: 6

Kurubaran
Kurubaran

Reputation: 8902

You can use msiexec.exe. You can simply install an MSI by passing the MSI path. Using command you can set whether to show UI during the installation or make it a silent installation,

string installCommandString = "/i {0} /qn";

  • /qn: Set user interface level: None
  • /qb: Set user interface level: Basic UI
  • /qr: Set user interface level: Reduced UI
  • /qf: Set user interface level: Full UI (default)

C# code

string installCommandString = "/i {0} /qn";

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
process.StartInfo = startInfo;

startInfo.UseShellExecute = false;
startInfo.RedirectStandardError = true;

startInfo.FileName = "msiexec.exe";
startInfo.Arguments = string.Format(installCommandString, "SQL Server MSI Path");

process.Start();

Upvotes: 1

Andrew
Andrew

Reputation: 2335

If you are using the standard MSI installer, built into Visual Studio then there is an option to set pre-requisites.

  • Right click the MSI
  • Select properties
  • Select prerequisites

Near the bottom there is an option for SQL Server Express and you can specify where to get the components from - vendor, or from a location on your servers.

Upvotes: 0

Related Questions