我想创建一个简单的Web窗体,它会给我一个屏幕上的服务重启按钮。在ASP.net中使用SQL Server SMO访问被拒绝0x80070005
单击该按钮后,我创建了一个SMO对象来与SQL Server数据库对话并尝试停止并启动MSSQLSERVER
服务。一切顺利,直到Stop()
方法被调用,此时抛出异常,说明:
访问被拒绝。 (从HRESULT异常:0X80070005 (E_ACCESSDENIED))
按钮下的代码如下:
// connect the to server
ManagedComputer computer =
new ManagedComputer("172.16.150.52",@"Administrator","secret");
// return if there is a problem
if (computer.Services["MSSQLSERVER"] == null)
{
PageErrorMessage = "Bad or missing service \"MSSQLSERVER\"";
return;
}
// get the SQL Server Service
Service sqlServer = computer.Services["MSSQLSERVER"];
// is the server running?
if (sqlServer.ServiceState == ServiceState.Running)
sqlServer.Stop();
// wait for it to stop completely
int timeout = 0;
while (sqlServer.ServiceState != ServiceState.Stopped || timeout <= 60)
{
Thread.Sleep(1000);
sqlServer.Refresh();
timeout++;
}
if (timeout > 60)
{
PageErrorMessage = "Stop operation has timed out after 60secs";
return;
}
// start it again!
sqlServer.Start();
的IP地址,用户名&密码是100%正确。有谁知道为什么这会抛出一个AccessDenied
异常?
这是一个操作系统错误,而不是一个WMI或Smo的错误,所以你可能会在ServerFault上获得更好的响应。看到这里:http://technet.microsoft.com/en-us/library/ee692772.aspx#EEAA – Pondlife 2011-12-21 13:35:50
我不知道它的操作系统是这样的。我猜OP没有实现处理UAC的代码。 – 2011-12-24 11:47:29