SQL 服务器存储过程或重新启动的替代方法 SQL 服务器代理
SQL Server stored procedure or alternative method to restart SQL Server Agent
有various ways to restart the SQL Server Agent on a server, but I would like to do it from a stored procedure in one of my databases (on the same server). How would one go about doing that? Is there some sort of a system stored procedure that I could call? Or would I need to call some sort of third party library/external language to accomplish that such as the following?
显然我的 co-workers 之一已经解决了这个问题:
EXEC xp_servicecontrol N'STOP',N'SQLServerAGENT';
-- Give the service a little time to stop
waitfor delay '00:00:10.000'
EXEC xp_servicecontrol N'START',N'SQLServerAGENT';
不确定这是最好的解决方案,但应该适合我的目的...
根据具体情况,PowerShell 可能是一种不错的方法。 Start-Service 和 Restart-Service 命令将是一个很好的起点 :O
有various ways to restart the SQL Server Agent on a server, but I would like to do it from a stored procedure in one of my databases (on the same server). How would one go about doing that? Is there some sort of a system stored procedure that I could call? Or would I need to call some sort of third party library/external language to accomplish that such as the following?
显然我的 co-workers 之一已经解决了这个问题:
EXEC xp_servicecontrol N'STOP',N'SQLServerAGENT';
-- Give the service a little time to stop
waitfor delay '00:00:10.000'
EXEC xp_servicecontrol N'START',N'SQLServerAGENT';
不确定这是最好的解决方案,但应该适合我的目的...
根据具体情况,PowerShell 可能是一种不错的方法。 Start-Service 和 Restart-Service 命令将是一个很好的起点 :O