SQL Server Agent のエラー ログを読み取るには

SQL Server 2008 で SQL Server Agent サービスのエラー ログを Transact-SQL から読み取るには、次のように xp_ReadErrorLog 拡張ストアド プロシージャを利用します。

xp_ReadErrorLog 0,2

第1引数の 0 は現在のログ、2 は SQL Server Agent サービスのログという意味です。アーカイブの 1つ目のログを読み取りたい場合は「xp_ReadErrorLog 1,2」と実行します。
第2引数は 1 を指定することで、SQL Server ログを読み取ることができます。


ただし、xp_ReadErrorLog の利用の際には、以下の KB973524 にあるように SP1 CU4 を適用しておくことをお勧めします。

FIX: The execution of the xp_readerrorlog command in SQL Server 2005 and in SQL Server 2008 stops responding and the usage of the CPU that is running the command increases to 100 percent
http://support.microsoft.com/kb/973524/en-us