读取SQL的Agent代理的日志文件

读取SQL的Agent代理的日志文件,第1张

概述读取SQL的Agent代理的日志文件

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

use msdbgoif exists (select * from sysobjects where name = N'sp_sqlagent_read_errorlog' and type ='P')    drop proc dbo.sp_sqlagent_read_errorloggocreate proc dbo.sp_sqlagent_read_errorlog @fiLeversion int = nullasset nocount ondeclare @rc intdeclare @version intdeclare @pos intdeclare @errorlog_file nvarchar(255)declare @filename nvarchar(255)declare @filename_no_ext nvarchar(255)declare @dirname nvarchar(255)declare @buf nvarchar(255)-- sql Server 7.0if (charindex(N'7.00',@@version,0) > 0)begin    exec @rc = master.dbo.xp_regread         N'HKEY_LOCAL_MACHINE',N'SOFTWARE\Microsoft\MSsqlServer\sqlServerAgent',N'ErrorLogfile',@errorlog_file OUTPUT,N'no_output'end-- sql Server 2000 needs to use instance aware Registry read if (charindex(N'8.00',0) > 0)begin    exec @rc = master.dbo.xp_instance_regread         N'HKEY_LOCAL_MACHINE',N'no_output'end-- reverse the string to find the last slash '\'select @buf = reverse(@errorlog_file)-- determine posiktion of last slash,Now first slash in reversed stringselect @pos = len(@buf) - charindex(char(92),@buf,0) + 1-- extract the directory only part,part before the last slashselect @dirname = substring(@errorlog_file,@pos)-- extract the filename,part after the last slashselect @filename = substring(@errorlog_file,@pos + 1,len(@errorlog_file) - @pos)-- extract the filename with extension,part after dot in @filenameselect @filename_no_ext  = substring(@filename,charindex(N'.',@filename,0))-- change errorlog file to version Xif (@fiLeversion is not null)    select @errorlog_file = @dirname +N'\' +  @filename_no_ext + N'.' + convert(nchar,@fiLeversion)-- read fileexec master.dbo.xp_readerrorlog 1,@errorlog_filego-- sample usage-- read currently active log file,sqlAGENT.OUT-- exec msdb.dbo.sp_sqlagent_read_errorlog-- read version 1 of log,sqlAGENT.1-- exec msdb.dbo.sp_sqlagent_read_errorlog 1

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的读取SQL的Agent代理的日志文件全部内容,希望文章能够帮你解决读取SQL的Agent代理的日志文件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1165171.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存