简体   繁体   English

卸载SQL Server Express 2005,然后在C#ClickOnce Winform应用程序中安装SQL Server 2008 R2 Express

[英]Uninstall SQL Server Express 2005 then install SQL Server 2008 R2 Express in C# ClickOnce Winform App

My app is deployed internally using ClickOnce and has a prerequisite of SQL Server 2005 Express. 我的应用程序使用ClickOnce在内部部署,并具有SQL Server 2005 Express的先决条件。

I want to upgrade my user's to SQL Server 2008 R2 Express. 我想将我的用户升级到SQL Server 2008 R2 Express。 What are my options that don't involve me 'touching' all 300 laptops? 我的选择是什么,不涉及我'触摸'所有300台笔记本电脑?

My idea, in theory only, was to drop the SQL Server Express prereq completely, put an 'upgrade' prompt in my app and give the users a couple days to click it, then re-add SQL Server Express as a prereq but as the new version. 理论上,我的想法是完全放弃SQL Server Express先决条件,在我的应用程序中放置“升级”提示并给用户几天时间点击它,然后重新添加SQL Server Express作为先决条件,但作为新版本。

I think this would work though I am open to suggestions otherwise. 我认为这会奏效,但我愿意接受其他建议。 However, my actual question is how I can accomplish my 'upgrade' prompt. 但是,我的实际问题是如何完成“升级”提示。 How do I uninstall SQL Server Express in a C# Winform app? 如何在C#Winform应用程序中卸载SQL Server Express?

Thanks, 谢谢,

See this MSDN article on how to install SQL Server 2008 R2 silently (but why not do 2012 instead? :) 请参阅此MSDN文章 ,了解如何以静默方式安装SQL Server 2008 R2(但为什么不改为使用2012?:)

A quick cheat is (I have done this with non express editions, but should be the same process) to go through manual upgrade first to gather all the answers for the config and settings, and just before executing actual upgrade, in the final step you should see towards the bottom a path to the answer (ini) file (see below image), if you cancel and grab that file, you can run it in command line like Setup.exe /ConfigurationFile=MyConfigurationFile.INI 快速作弊(我已经完成了非快速版本,但应该是相同的过程)首先进行手动升级以收集配置和设置的所有答案,并执行实际升级之前 ,在最后一步中应该在底部看到一个回答(ini)文件的路径(见下图),如果你取消并获取该文件,你可以在命令行中运行它,如Setup.exe /ConfigurationFile=MyConfigurationFile.INI

在此输入图像描述

Once you test it out, you should be able to create something that pulls the binaries and answer file into the user's pc, and spawn a process to run the setup in silent mode. 一旦你测试了它,你应该能够创建一些东西,将二进制文件和应答文件拉入用户的电脑,并产生一个进程以静默模式运行安装程序。 Though you should make sure your users are admins first of course. 虽然您应该首先确保您的用户是管理员。

To Uninstall: Run setup with the uninstall option like Setup.exe /Action=Uninstall /FEATURES=SQL,AS,RS,IS,Tools /INSTANCENAME=MSSQLSERVER , see the Uninstall Parameters section. 要卸载:使用卸载选项运行安装程序,如Setup.exe /Action=Uninstall /FEATURES=SQL,AS,RS,IS,Tools /INSTANCENAME=MSSQLSERVER ,请参阅卸载参数部分。 If my memory serves me well, you can actually just do Setup.exe /Action=Uninstall /INSTANCENAME=MSSQLSERVER to remove everything for the particular instance you wish to remove, but I may be wrong, so test first 如果我的记忆很好,你可以实际上只做Setup.exe / Action = Uninstall / INSTANCENAME = MSSQLSERVER来删除你要删除的特定实例的所有内容,但我可能是错的,所以先测试一下

I'm working on a similar requirement to automate an upgrade from SQL 2005 Express to SQL 2008 R2 Express from a WinForms application. 我正在制定类似的要求,从WinForms应用程序自动从SQL 2005 Express升级到SQL 2008 R2 Express。

You don't actually have to uninstall SQL 2005 to do the upgrade. 您实际上不必卸载SQL 2005来进行升级。 You can just upgrade straight from 2005 to 2008R2 without any uninstall required. 您可以直接从2005升级到2008R2,无需任何卸载。

My code looks something like this (modified to simplify and remove proprietary stuff)... 我的代码看起来像这样(修改为简化和删除专有的东西)...

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM