[英]Uninstall SQL Server Express 2005 then install SQL Server 2008 R2 Express in C# ClickOnce Winform App
我的应用程序使用ClickOnce在内部部署,并具有SQL Server 2005 Express的先决条件。
我想将我的用户升级到SQL Server 2008 R2 Express。 我的选择是什么,不涉及我'触摸'所有300台笔记本电脑?
理论上,我的想法是完全放弃SQL Server Express先决条件,在我的应用程序中放置“升级”提示并给用户几天时间点击它,然后重新添加SQL Server Express作为先决条件,但作为新版本。
我认为这会奏效,但我愿意接受其他建议。 但是,我的实际问题是如何完成“升级”提示。 如何在C#Winform应用程序中卸载SQL Server Express?
谢谢,
请参阅此MSDN文章 ,了解如何以静默方式安装SQL Server 2008 R2(但为什么不改为使用2012?:)
快速作弊(我已经完成了非快速版本,但应该是相同的过程)首先进行手动升级以收集配置和设置的所有答案,并在执行实际升级之前 ,在最后一步中应该在底部看到一个回答(ini)文件的路径(见下图),如果你取消并获取该文件,你可以在命令行中运行它,如Setup.exe /ConfigurationFile=MyConfigurationFile.INI
一旦你测试了它,你应该能够创建一些东西,将二进制文件和应答文件拉入用户的电脑,并产生一个进程以静默模式运行安装程序。 虽然您应该首先确保您的用户是管理员。
要卸载:使用卸载选项运行安装程序,如Setup.exe /Action=Uninstall /FEATURES=SQL,AS,RS,IS,Tools /INSTANCENAME=MSSQLSERVER
,请参阅卸载参数部分。 如果我的记忆很好,你可以实际上只做Setup.exe / Action = Uninstall / INSTANCENAME = MSSQLSERVER来删除你要删除的特定实例的所有内容,但我可能是错的,所以先测试一下
我正在制定类似的要求,从WinForms应用程序自动从SQL 2005 Express升级到SQL 2008 R2 Express。
您实际上不必卸载SQL 2005来进行升级。 您可以直接从2005升级到2008R2,无需任何卸载。
我的代码看起来像这样(修改为简化和删除专有的东西)...
try
{
//First, find the version of the currently installed SQL Server Instance
string sqlString = "SELECT SUBSTRING(CONVERT(VARCHAR, SERVERPROPERTY('productversion')), 0, 5)";
string sqlInstanceVersion = string.Empty;
//_database was initialized elsewhere - it's from Enterprise Library
using (DbCommand cmd = _database.GetSqlStringCommand(sqlString))
{
sqlInstanceVersion = cmd.ExecuteScalar().ToString();
}
if (sqlInstanceVersion.Equals(String.Empty))
{
//TODO throw an exception or do something else
}
//11.00 = SQL2012, 10.50 = SQL2008R2, 10.00 = SQL2008, 9.00 = SQL2005, 8.00 = SQL2000
switch (sqlInstanceVersion)
{
case "11.00":
case "10.50":
case "10.00":
//Log that the version is already up to date and return
return;
case "9.00":
case "8.00":
//We are on SQL 2000 or 2005, so continue with upgrade to 2008R2
break;
default:
//TODO throw an exception for unsupported SQL Server version
break;
}
string upgradeArgumentString = "/Q /ACTION=upgrade /INSTANCENAME={0} /ENU /IACCEPTSQLSERVERLICENSETERMS";
string instanceName = "YourInstanceNameHere";
string installerFilePath = AppDomain.CurrentDomain.BaseDirectory + "\\SQLEXPR_x86_ENU.exe";
if (!File.Exists(installerFilePath))
{
throw new FileNotFoundException(string.Format("Unable to find installer file: {0}", installerFilePath));
}
Process process = new Process
{
StartInfo = { FileName = installerFilePath, Arguments = String.Format(upgradeArgumentString, instanceName), UseShellExecute = false }
};
process.Start();
if (process.WaitForExit(SQLSERVER_UPGRADE_TIMEOUT))
{
//Do something here when the process completes within timeout.
//Probably look at exit code, or whatever to determine if it was successful
}
else
{
//The process exceeded timeout. Do something about it; like throw exception, or whatever
}
}
catch(Exception ex)
{
//Handle your exceptions here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.