SQL Server 2012授予从ASP.net访问sys.dm_os_ring_buffers的权限

时间:2014-02-25 04:23:28

标签: asp.net sql-server sql-server-2012 database-permissions

我想从ASP.Net应用程序中访问系统表。目前,应用程序使用用户帐户StudentPortal连接到数据库WebAppClient

当我尝试运行以WebAppClient登录的以下查询时,我收到错误:

  

用户无权执行此操作。

如何授予访问权限以便我的用户帐户可以查询该系统表?

这是我的完整查询:

SELECT TOP 1
     100 - r.SystemIdle AS CPU
FROM (
    SELECT
        rx.record.value('(./Record/@id)[1]', 'int') AS record_id,
        rx.record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int') AS SystemIdle
    FROM (
        SELECT CONVERT(XML, record) AS record
        FROM sys.dm_os_ring_buffers
        WHERE
            ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR' AND
            record LIKE '%<SystemHealth>%') AS rx
    ) AS r
ORDER BY r.record_id DESC

1 个答案:

答案 0 :(得分:2)

必须授予用户“查看服务器状态”权限才能查看sys DMV。

以下是MS KB article.

实际声明:GRANT View Server STATE TO <user>