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.
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";
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With