Dynamics 365 报表使用日志记录查询及相关扩展

Dynamics 365 报表使用日志记录查询及相关扩展

获取用户查询报表的历史记录

select SUBSTRING( cl.Description,1,LEN(cl.Description)-1) reportname,  --报表名称 除去最后的冒号
	   sur.FullName,   --用户名
	   sur.DomainName, --域账号
	   ex.TimeStart    --开始时间
from ReportServer.dbo.ExecutionLogStorage ex 
inner join ReportServer.dbo.Catalog cl on cl.ItemID = ex.ReportID
inner join SystemUser sur on sur.SystemUserId = SUBSTRING(ex.Parameters,8,36)
where SUBSTRING( ex.Parameters,1,7) = 'userid=' -- 筛选用户账号登录的信息

注意:

  1. 如果报表重新部署了,则报表ID会发生变化导致历史记录查不到。
  2. ReportServer.dbo.ExecutionLogStorage 这张表好像只存储不到两个月的记录
    但是这张表是系统自带的表 不敢乱搞 因为如果想要记录更久的记录只能曲线救国

备份表“曲线救国”

每天对 ExecutionLogStorage 表中新增的数据写到备份表中,查询数据时在备份表中查询数据。
在查询数据时遇到一个问题

-- 如下SQL 为在备份表中插入今天(2021年1月12日)的记录
insert into ReportServer.dbo.new_reports_log select * from ReportServer.dbo.ExecutionLogStorage where TimeStart > '2021-01-12 00:00:00.00'

执行时报错了
仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表’ReportServer.dbo.new_reports_log’中的标识列指定显式值。

这是因为:
在有自增长的SQL表格里面插入指定ID的数据的时候,会禁止操作

所以需要两点:

  1. 把 ReportServer.dbo.new_reports_log 的 IDENTITY_INSERT 设置为 ON
  2. 不能省略列名

因此上面的SQL要改成如下:

set identity_insert ReportServer.dbo.new_reports_log ON;

INSERT ReportServer.dbo.new_reports_log 
(LogEntryId,InstanceName,ReportID,UserName,ExecutionId,RequestType,Format,Parameters,
ReportAction,TimeStart,TimeEnd,TimeDataRetrieval,TimeProcessing,TimeRendering,Source,Status,ByteCount,[RowCount],AdditionalInfo) 
SELECT LogEntryId,InstanceName,ReportID,UserName,ExecutionId,RequestType,Format,Parameters,
ReportAction,TimeStart,TimeEnd,TimeDataRetrieval,TimeProcessing,TimeRendering,Source,Status,ByteCount,[RowCount],AdditionalInfo
FROM ReportServer.dbo.ExecutionLogStorage 
WHERE TimeStart > '2021-01-12 00:00:00.00';

SET identity_insert ReportServer.dbo.new_reports_log OFF;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mu_sang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值