以编程方式安装SQL Server 2012 Express [英] Install SQL Server 2012 Express Programmatically

查看:120
本文介绍了以编程方式安装SQL Server 2012 Express的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在安装应用程序上安装WPF产品的所有要求,其中一项要求是SQL Server 2012 Express,下面的代码是在生成用于静默安装的配置文件后进行安装:

I work on Setup application to install all requirement for my WPF product, one of the requirement is SQL Server 2012 Express, the code below is to install it after I generate the configuration file for silent installation :

private void SetupSQLServer()
{
        string result = "";
        string commandLine = "";

        if (os64)
            commandLine = string.Format(@"{0}\SQLServer\sql64\setup.exe PCUSOURCE={0}\SQLServer\sql64 /SAPWD=""p@ssw0rd"" /CONFIGURATIONFILE={0}\SQLServer\ConfigurationFile64.ini /HIDECONSOLE", setupFolder);
        else
            commandLine = string.Format(@"{0}\SQLServer\sql86\setup.exe PCUSOURCE={0}\SQLServer\sql86 /SAPWD=""p@ssw0rd"" /CONFIGURATIONFILE={0}\SQLServer\ConfigurationFile32.ini /HIDECONSOLE", setupFolder);

        startInfo.WorkingDirectory = setupFolder;
        startInfo.Arguments = "/c " + commandLine;
        startInfo.RedirectStandardOutput = true;
        startInfo.UseShellExecute = false;

        process.StartInfo = startInfo;

        try
        {
            process.Start();
        }
        catch (Exception e)
        {
            result = e.Message;
        }

        result = result + "\n" + process.StandardOutput.ReadToEnd();

        UpdateStepResult(result);
    }

代码没有错误,但是在我运行时不起作用

There's no error in the code but it does not work .. when I run the code the command window appear and disappear and nothing happen.

UPDATE:

使用时:

fileName = string.Format(@"{0}\SQLServer\sql64\setup.exe", setupFolder);

运行安装但没有配置文件,使用时:

The installation is run but without configuration file, when I used:

fileName = string.Format(@"{0}\SQLServer\sql64\setup.exe /CONFIGURATIONFILE={0}\SQLServer\sql64\ConfigurationFile64.ini", setupFolder);

它给了我这个错误系统找不到指定的文件!
该文件存在于同一文件夹中!

It gives me this error "The system cannot find the file specified" !!! The file is exist in the same folder !!

请帮助我发现错误。

预先感谢。

推荐答案

ProcessStartInfo要求FileName属性有效。上面的代码没有设置代码,而是将所有参数作为参数传递。

The ProcessStartInfo requires the FileName property to be valid. Your code above doesn't set it but pass everything as Arguments.

可能您需要将命令行分为两部分。如果(os64)
{
fileName = string,则要运行的可执行文件和要传递的参数

Probably you need to separate the command line in two parts. The Executable to run and the arguments to pass

   if (os64)
   {
        fileName = string.Format("{0}\SQLServer\sql64\setup.exe", setupFolder);
        commandLine = string.Format(@"PCUSOURCE={0}\SQLServer\sql64 /SAPWD=""p@ssw0rd"" /CONFIGURATIONFILE={0}\SQLServer\ConfigurationFile64.ini /HIDECONSOLE", setupFolder);
    }
    else
    {
         // Same for 32 bit
         .....
    }
    ....
    startInfo.FileName = fileName;
    .... 

这篇关于以编程方式安装SQL Server 2012 Express的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆