Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 832
Rama Avatar asked Sep 19 '25 21:09

Rama


2 Answers

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.

like image 118
Remus Rusanu Avatar answered Sep 22 '25 12:09

Remus Rusanu


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();
like image 22
Kurubaran Avatar answered Sep 22 '25 12:09

Kurubaran