天天看点

服务器重启后SQL Server Agent由于"The EventLog service has not been started" 启动失败

案例环境:

    操作系统   : microsoft windows server 2003 standard edtion sp2

    数据库版本 : sql server 2005 standard edition sp4

案例描述:

服务器重启过后,mssqlserver服务自动重启了,但是sqlserveragent服务启动失败(当然sql

agent服务的启动类型为自动启动(automatic)),在这台服务器第二次遇到这种情况,第一次遇到时没太注意,以为只是特殊案例,直到在这台服

务器第二次遇到这种情况,才感觉有点奇怪。

服务器重启后SQL Server Agent由于"The EventLog service has not been started" 启动失败
服务器重启后SQL Server Agent由于"The EventLog service has not been started" 启动失败

查 sql server agent's log日志发现如下错误信息:[241] startup error: unable to

initialize error reporting system (reason: the eventlog service has not

been started)

服务器重启后SQL Server Agent由于"The EventLog service has not been started" 启动失败

境为sql server 2000)解释这个是sql server agent代码里面的一个bug来的:作为sql

server代理的启动任务的一部分,它初始化一个记录组件,将错误、

警告或信息性消息报告给代理的日志文件(sqlagent.out),如果它在任何非win9x的平台上运行,事件日志(通过事件日志服务的

windows

api)作为初始化过程的一部分,它必须确保该事件日志服务已启动,因为如果不是这样,那么该代理无法正常运作,报上述错误后退出。..........

博客具体内容如下所示

it happened to be a bug in sql server agent's code, and here's a brief explanation of what it is:

as

part of sql server agent's startup tasks, it initializes a logging

component, which will report errors, warnings, or informational messages

to agent's log file (sqlagent.out) and, if it's running on any non

win9x platforms, to the event log (by using the eventlog service windows

apis). so, as part of that initialization process, it has to make sure

that the eventlog service is started, because if it isn't, then the

agent cannot function properly and so it exits with the error described

above.

twice with service_active as the value for its dwservicestate parameter

(so it will only enumerate services that are in the following states:

service_start_pending, service_stop_pending, service_running,

service_continue_pending, service_pause_pending, or service_paused).

the

first call to that api passes null to the lpservices parameter and zero

for cbbufsize, that to only determine the size of the buffer required

to hold the list of services in such states at the moment of the call.

later, it allocates as many bytes as the pcbbytesneeded parameter

again. if at the time of the second call to enumservicesstatus there

are more services in any of the states mentioned earlier, than during

function implemented in sql server agent to check whether eventlog is

running or not, doesn't take into account such "exceptional" condition

and simply returns a failure as if the eventlog service wouldn't be

running.

不过由于作者描述的情况发生在sql

server 2000环境下,而我对比了手头其他一样环境的sql server

2005的服务器,都没有这个问题,只有这台服务器出现这个问题,所以弄不清到底是sql server

agent的bug还是操作系统环境问题所致。不过猜测跟上面博客里面所叙说的那样跟eventlog服务有一定关系。

解决方法

服务器重启后SQL Server Agent由于"The EventLog service has not been started" 启动失败
服务器重启后SQL Server Agent由于"The EventLog service has not been started" 启动失败