如何以编程方式安装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();


       }