Wednesday 19 April 2023

C# – 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.


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.

No comments:

Post a Comment