如何以编程方式更改SQL Server 2005 Express Edition配置
问题描述:
我已添加SQL Server Express版本作为先决条件,因此它会自动安装在计算机上.
但是在安装时,将SQL身份验证模式设置为Windows,将TCP/IP设置设置为禁用.
现在建议我在计算机上安装SQL之后如何以编程方式更改上述设置.
I have added SQL Server express edition as a prerequisite so it automatically installs on computer.
But at the time of installing it set SQL authentication mode as windows and TCP/IP settings as disabled.
Now suggest me how do i change the above settings programatically after SQL installed on computer.
答
SQL Server管理对象(SMO)是为以下目的而设计的对象的集合对管理Microsoft SQL Server的所有方面进行编程.参考: http://msdn.microsoft.com/en-us/library/ms162169.aspx [ ^ ]
SQL Server Management Objects (SMO) is a collection of objects that are designed for programming all aspects of managing Microsoft SQL Server. Reference at: http://msdn.microsoft.com/en-us/library/ms162169.aspx[^]
private void button1_Click(object sender, EventArgs e)
{
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Application.StartupPath.Trim() + @"\SqlServer2005 Express\SQLEXPR.EXE";
//-q[n|b|r|f] Sets user interface (UI) level:
//n = no UI
//b = basic UI (progress only, no prompts)
//r = reduced UI (dialog at the end of installation)
//f = full UI
psi.Arguments = "/qb username=\"sa\" companyname=\"Rumtek\" addlocal=ALL disablenetworkprotocols=\"0\" instancename=\"SQLExpress\" SECURITYMODE=\"SQL\" SAPWD=\"lock\"";
p.StartInfo = psi;
p.Start();
}
private void button2_Click(object sender, EventArgs e)
{
//Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll", "TcpPort", "1433");
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer\SuperSocketNetLib\Tcp\IPAll", "TcpPort", "1433");
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Application.StartupPath.Trim() + @"\command\cmd.exe";
psi.Arguments = "NET STOP MSSQL
SQLExpress"; p.StartInfo = psi; p.Start(); 进程p1 = new Process(); ProcessStartInfo psi1 =新的ProcessStartInfo(); psi1.FileName = Application.StartupPath.Trim()+ @"\ command \ cmd.exe"; psi1.Arguments ="NET START MSSQL
SQLExpress"; p.StartInfo = psi; p.Start(); Process p1 = new Process(); ProcessStartInfo psi1 = new ProcessStartInfo(); psi1.FileName = Application.StartupPath.Trim() + @"\command\cmd.exe"; psi1.Arguments = "NET START MSSQL