如何以编程方式安装SQL Server Express R2 2008 [英] How to Install SQL Server Express R2 2008 Programatically

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

问题描述

嗨朋友们,



我在本地硬盘上安装了SQL Server Express R2 2008,现在我想用c#.net运行安装程序。



string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+\\SQLEXPR.exe;

流程psql = new流程();

psql.StartInfo.FileName = path;

psql.StartInfo.Arguments = @/ qs / Action = Install / Hideconsole / IAcceptSQLServerLicenseTerms =True / Features = SQL,Tools / INSTANCENAME = \SQLEXPRESS \INSTALLSQLDIR = \c:\\Program Files \\ Microsoft SQL Server \INSTALLSQLSHAREDDIR = \ c:\\Program Files \\ Microsoft Microsoft SQL Server \INSTALLSQLDATADIR = \C:\\Program Files \\ Microsoft SQL Server \ADDLOCAL = \所有\SQLAUTOSTART = 1 SQLBROWSERAUTOSTART = 1 SQLBROWSERACCOUNT = \NT AUTHORITY \ \\ SYSTEM \SQLACCOUNT = \NT AUTHORITY \\NETWORK SERVICE \SECURITYMODE = SQL SAPWD = \\SQLCOLLATION = \SQL_Latin1_General_Cp1_CS_AS \ERRORREPORTING = 1 ENABLERANU DISABLENETWORKPROTOCOLS = 0 = 0;



psql.StartInfo.CreateNoWindow = true;

Hi Friends,

I have SQL Server Express R2 2008 setup in my local hard disk, now i want run the setup using c#.net.

string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\SQLEXPR.exe";
Process psql = new Process();
psql.StartInfo.FileName = path;
psql.StartInfo.Arguments = @"/qs /Action=Install /Hideconsole /IAcceptSQLServerLicenseTerms=""True"" /Features=SQL,Tools /INSTANCENAME = \""SQLEXPRESS\""INSTALLSQLDIR = \""c:\\Program Files\\Microsoft SQL Server\""INSTALLSQLSHAREDDIR = \""c:\\Program Files\\Microsoft SQL Server\""INSTALLSQLDATADIR = \""C:\\Program Files\\Microsoft SQL Server\""ADDLOCAL = \""All \""SQLAUTOSTART = 1 SQLBROWSERAUTOSTART = 1 SQLBROWSERACCOUNT = \""NT AUTHORITY\\SYSTEM\""SQLACCOUNT = \""NT AUTHORITY\\NETWORK SERVICE\""SECURITYMODE = SQL SAPWD = \""\""SQLCOLLATION = \""SQL_Latin1_General_Cp1_CS_AS\""ERRORREPORTING = 1 ENABLERANU DISABLENETWORKPROTOCOLS = 0 = 0""";

psql.StartInfo.CreateNoWindow = true;

psql.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
psql.Start();

  psql.WaitForExit();







i使用上面的代码吧已安装,但我正在尝试打开连接它正在抛出错误



''发生与网络相关或特定于实例的错误同时建立与SQL Server的连接。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供者:命名管道提供程序,错误:40 - 无法打开与SQL Server的连接)''





请可以任何一个建议我



先谢谢




i used the above code it''s installed, but i''m trying to open the connection it''s throwing the Error

''A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)''


Please can any one suggest me

Thanks in Advance

推荐答案

private void InstallSQlServer()
       {
           ProcessStartInfo startinfo = new ProcessStartInfo();
           startinfo.FileName = "cmd.exe";
           startinfo.RedirectStandardInput = true;
           startinfo.RedirectStandardOutput = true;
           startinfo.UseShellExecute = false;
           // startinfo.CreateNoWindow = true;
           myprocess.StartInfo = startinfo;
           myprocess.Start();
           System.IO.StreamReader SR = myprocess.StandardOutput;
           System.IO.StreamWriter SW = myprocess.StandardInput;
           SW.WriteLine(@"""C:\Users\Administrator\Desktop\SQL Express UnAttended Installation\SQLEXPRADV_x86_ENU.exe"" /ConfigurationFile= ""C:\Users\Administrator\Desktop\SQL Express UnAttended Installation\Configuration.ini"" /IACCEPTSQLSERVERLICENSETERMS /Q /SAPWD=""exp2oo8@r2"" ");
           myprocess.WaitForExit();
           MessageBox.Show(SR.ReadToEnd());
           SW.WriteLine("exit");
           SW.Flush();
           SR.Close();


       }


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

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