我要用代码关闭和打开Sql serve2000总是提示“System.ComponentModel.Win32Exception:拒绝访问”
代码如下
------------------------------------------------------------------------------------------
System.ServiceProcess.ServiceController sc2 = new System.ServiceProcess.ServiceController("MSSQLSERVER");
if (sc2.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Stopped))
{
sc2.Start();
}
else
{
sc2.Stop();
}
------------------------------------------------------------------------------------------
错误提示如下
------------------------------------------------------------------------------------------
拒绝访问。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问。源错误:
行 85: else
行 86: {
行 87: sc2.Stop();
行 88: }
行 89:
源文件: c:\inetpub\wwwroot\webapplication3\webform1.aspx.cs 行: 87 堆栈跟踪:
[Win32Exception (0x80004005): 拒绝访问。][InvalidOperationException: 无法打开计算机“.”上的 MSSQLSERVER 服务。]
System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess) +175
System.ServiceProcess.ServiceController.Stop() +92
WebApplication3.WebForm1.Button2_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication3\webform1.aspx.cs:87
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
------------------------------------------------------------------------------------------
该如何解决?
代码如下
------------------------------------------------------------------------------------------
System.ServiceProcess.ServiceController sc2 = new System.ServiceProcess.ServiceController("MSSQLSERVER");
if (sc2.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Stopped))
{
sc2.Start();
}
else
{
sc2.Stop();
}
------------------------------------------------------------------------------------------
错误提示如下
------------------------------------------------------------------------------------------
拒绝访问。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问。源错误:
行 85: else
行 86: {
行 87: sc2.Stop();
行 88: }
行 89:
源文件: c:\inetpub\wwwroot\webapplication3\webform1.aspx.cs 行: 87 堆栈跟踪:
[Win32Exception (0x80004005): 拒绝访问。][InvalidOperationException: 无法打开计算机“.”上的 MSSQLSERVER 服务。]
System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess) +175
System.ServiceProcess.ServiceController.Stop() +92
WebApplication3.WebForm1.Button2_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication3\webform1.aspx.cs:87
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
------------------------------------------------------------------------------------------
该如何解决?
解决方案 »
- 内容页中控制母版页的自定义控件是否显示!
- 往excel表插入数据
- ASP.NET动态画系统结构图。有人来看看么。。。
- System.Diagnostics.Process.Start 未知的用户名或错误密码
- 还是listbox的一个问题
- 如何不让用户粘贴信息到TEXTBOX
- ASP课程设计
- 又是正则表达式
- asp.net 如何获取windows剪切板里的内容?? 另:能不能获取客户端的?
- 将datetime转换成bigint格式如 20021001235959
- 【【当鼠标移动到Dropdownlist中的某一选项,如何设置被聚焦选项的前景色?】】
- 当鼠标移动到Dropdownlist中的某一选项,如何设置被聚焦选项的前景色?
2、连接字符串格式是否正确:
data source=myserver;initial catalog=northwind;user id=userid;password=password
试试
常用的一些连接字符串(C#代码):
SqlConnection conn
= new SqlConnection( "Server=(local);Integrated Security=SSPI;database=Pubs");
SqlConnection conn
= new SqlConnection("server=(local)\\NetSDK;database=pubs;Integrated Security=SSPI");
SqlConnection conn = new SqlConnection(
"Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;");
SqlConnection conn = new SqlConnection(
" data source=(local);initial catalog=xr;integrated security=SSPI;
persist security info=False;workstation id=XURUI;packet size=4096; ");
SqlConnection myConn = new
System.Data.SqlClient.SqlConnection("Persist Security Info=False;Integrated
Security=SSPI;database=northwind;server=mySQLServer");
SqlConnection conn = new SqlConnection(
" uid=sa;pwd=passwords;initial catalog=pubs;data source=127.0.0.1;Connect Timeout=900");