When you rely on jobs in SQL Server, it can be quite frustrating when SQL Server Agent has stopped and either it's not set to auto-restart, or you are using an older version of SQL Server where this option didn't exist. So if you can't connect to the database using Enterprise Manager or Query Analyzer, you can write up a quick ASP script that connects to the database and starts the service (assuming the SQL Server service is started, and that the user has appropriate permissions to execute such a command):
<% set conn = CreateObject("ADODB.Connection") conn.open "<connectionString>" sql = "EXEC master.dbo.xp_ServiceControl 'QUERYSTATE','SQLServerAgent'" set rs = conn.execute(sql) if trim(rs(0)) <> "Running." then response.write "Starting SQL Server Agent..." sql = "EXEC master.dbo.xp_ServiceControl 'START', 'SQLServerAgent'" conn.execute(sql) else response.write "SQL Server Agent already started..." end if conn.close set conn = nothing %> |
Keep in mind that xp_ServiceControl is undocumented and unsupported; its behavior could change with a service pack or the next release of SQL Server. If this is a concern, you can consider using msdb.dbo.sp_start_job. For a few examples, see
Article #2194.