zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

server服务器SQL 启动 The not 失败 quot
2023-09-14 08:57:52 时间

案例环境:

    操作系统   : Microsoft Windows Server 2003 Standard Edtion SP2

    数据库版本 : SQL Server 2005 Standard Edition SP4

 

案例描述:

    服务器重启过后,MSSQLSERVER服务自动重启了,但是SQLSERVERAGENT服务启动失败(当然SQL Agent服务的启动类型为自动启动(Automatic)),在这台服务器第二次遇到这种情况,第一次遇到时没太注意,以为只是特殊案例,直到在这台服 务器第二次遇到这种情况,才感觉有点奇怪。

clipboard

clipboard[1]

查 SQL Server Agents log日志发现如下错误信息:[241] Startup error: Unable to initialize error reporting system (reason: The EventLog service has not been started)

 

clipboard[2]

 

检查发现Event Log服务也正常启动了。在这篇文章SQL Server Agent failing to start because "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 Agents code, and heres a brief explanation of what it is:

As part of SQL Server Agents startup tasks, it initializes a Logging component, which will report errors, warnings, or informational messages to agents log file (SQLAGENT.OUT) and, if its 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 isnt, then the agent cannot function properly and so it exits with the error described above.

The function which checks whether the EventLog service is running or not, calls EnumServicesStatus 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 reflected that were needed, and finally it calls EnumServicesStatus again. If at the time of the second call to EnumServicesStatus there are more services in any of the states mentioned earlier, than during the first call to EnumServicesStatus, then it returns FALSE and GetLastError returns ERROR_MORE_DATA.

The function implemented in SQL Server Agent to check whether EventLog is running or not, doesnt take into account such "exceptional" condition and simply returns a failure as if the EventLog service wouldnt be running.

不过由于作者描述的情况发生在SQL SERVER 2000环境下,而我对比了手头其他一样环境的SQL SERVER 2005的服务器,都没有这个问题,只有这台服务器出现这个问题,所以弄不清到底是SQL Server Agent的bug还是操作系统环境问题所致。不过猜测跟上面博客里面所叙说的那样跟EventLog服务有一定关系。

 

解决方法

    没有尝试使用SQL Server Agent failing to start because "The EventLog service has not been started" 博客里面介绍的方法,我在SQL Server Agent服务的恢复(Recovery)选项里面,设置当服务启动失败时,采取“重新启动服务”的措施,如下所示,经过两次测试,发现这个方案也可以完满解决这个问题。

clipboard[3]

clipboard[4]

  


[ SQL Server ] 计算N个月前,N个月后的方法 #1. 计算N个月前的日期 #2. 计算N个月后的日期 #3. 月末最后一天的情况(计算从日数多的月到日数较少的月) #4. 月末最后一天的情况(计算从日数少的月到日数较多的月)
【SQL Server】数据库开发指南(三)面向数据分析的 T-SQL 编程技巧与实践 T-SQL 指的是 Transact-SQL,是一种针对 Microsoft SQL Server 数据库系统的 SQL 方言。T-SQL 扩展了标准 SQL 语言,提供了更多的功能和特性,包括事务处理、错误处理、游标处理、动态 SQL、存储过程、触发器、用户定义函数等等。
潇湘隐者 网名潇湘隐者/潇湘剑客、英文名Kerry,兴趣广泛,广泛涉猎,个性随意,不善言辞。执意做一名会写代码的DBA,混迹于IT行业
第十二届 BigData NoSQL Meetup — 基于hbase的New sql落地实践 立即下载