我要用代码关闭和打开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
------------------------------------------------------------------------------------------
该如何解决?

解决方案 »

  1.   

    你采用的是什么连接方式,SQL Server 集成安全性还是连接字符串??
      

  2.   

    用的Sql Server  用户名: sa  密码:为空
      

  3.   

    1、SQL Server的属性中的身份验证是不是设为SQL Server和windows
    2、连接字符串格式是否正确:
    data source=myserver;initial catalog=northwind;user id=userid;password=password
      

  4.   

    我用winform试了都可以,是不是ASP.NET用户的权限不够,该如何解决。
      

  5.   

    连接串问题
    试试
    常用的一些连接字符串(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");
      

  6.   

    To aoyo 该怎样使用模拟?