简体   繁体   English

使用C#Forms Application静默安装SQL Server

[英]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. 我有一个用C#开发的Windows应用程序,我需要将它安装在只安装了操作系统和.Net Framework的PC上。 Now I have to give an option to install SQL Server 2008 R2 Express edition on that PC, using this windows application. 现在,我必须使用此Windows应用程序在该PC上安装SQL Server 2008 R2 Express版本。 I have coded for installing/uninstalling a windows service, but struck with sql server installation. 我编写了安装/​​卸载Windows服务的代码,但是安装了sql server。 could someone help me out in doing this. 有人可以帮助我做这件事。

Follow the guidelines in How to Embed SQL Server Express in an Application . 请遵循如何在应用程序中嵌入SQL Server Express中的准则。 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. 它涵盖了您需要的一切 ,包括选择正确的分发,选择适当的安装方法(wpi与setup.exe)以及如何配置安装。 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#: wiki甚至还有一个关于如何检测以前的Express安装的C#代码,如何从C#调用SQL Express的WPI(Web平台安装程序):

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

or using the "wpi://" URL handler: 或使用“wpi://”URL处理程序:

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

or using the Web App Galery: 或使用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): 最后,使用SQL Express设置(建议用于高级配置):

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 . 您可以使用msiexec.exe You can simply install an MSI by passing the MSI path. 您只需通过传递MSI路径即可安装MSI。 Using command you can set whether to show UI during the installation or make it a silent installation, 使用命令可以设置是在安装过程中显示UI还是将其设置为静默安装,

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

  • /qn : Set user interface level: None / qn :设置用户界面级别:无
  • /qb : Set user interface level: Basic UI / qb :设置用户界面级别:基本UI
  • /qr : Set user interface level: Reduced UI / qr :设置用户界面级别:缩减UI
  • /qf : Set user interface level: Full UI (default) / qf :设置用户界面级别:完整UI(默认)

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 are using the standard MSI installer, built into Visual Studio then there is an option to set pre-requisites. 如果您使用的是Visual Studio内置的标准MSI安装程序,则可以选择设置先决条件。

  • Right click the MSI 右键单击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. 在底部附近有一个SQL Server Express选项,您可以指定从供应商或服务器上的某个位置获取组件的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 C# 应用程序安装 SQL Server Express - Install SQL Server Express with C# application 从应用程序安装文件静默安装SQL Server - Install SQL Server silently from application setup file 使用Windows窗体和C#将Excel文件保存在应用程序文件夹中并将内容上传到SQL Server - Saving excel file in application folder and uploading the content to SQL Server using windows forms and C# 使用SMO备份带有C#Windows Forms应用程序的SQL Server 2005数据库时,备份失败 - Using SMO to backup SQL Server 2005 Database with C# Windows Forms Application, Back up failed C# Windows 窗体应用程序 - 在文本框中显示 sql server 值 - C# Windows Forms Application - display sql server values in textbox 使用SQL Server2005的应用程序角色以C#的多种形式表示 - using application role of sql server2005 express in multiple forms in c# SQL Server Express C#应用程序安装组合 - SQL Server Express C# application install combination 使用C#和SQL的客户端服务器应用程序 - Client Server Application using C# and SQL C#应用使用SQL服务器数据库 - C# application using SQL Server database 使用我的应用程序C#安装SQL Server数据库 - install sql server database with my application c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM