Permission error when using sys.dm_exec_input_buffer with @@SPID
When I run this blob of SQL on SQL Server 2016 or an Azure SQL DB:
--hello world
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
WHERE req.session_id = @@SPID
I get this error, followed by the expected results:
Msg 300, Level 14, State 1, Line 5
VIEW SERVER STATE permission was denied on object 'server', database 'master'.
Msg 297, Level 16, State 1, Line 5
The user does not have permission to perform this action.
--hello world
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
WHERE req.session_id = @@SPID
The documentation for sys.dm_exec_input_buffer states (emphasis mine):
On SQL Server, if the user has VIEW SERVER STATE permission, the user will see all executing sessions on the instance of SQL Server; otherwise, the user will see only the current session.
Thus, according to the documentation, I am allowed to access this data. Why, then, is the error being raised?
sql-server sql-server-2016 azure-sql-database
add a comment |
When I run this blob of SQL on SQL Server 2016 or an Azure SQL DB:
--hello world
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
WHERE req.session_id = @@SPID
I get this error, followed by the expected results:
Msg 300, Level 14, State 1, Line 5
VIEW SERVER STATE permission was denied on object 'server', database 'master'.
Msg 297, Level 16, State 1, Line 5
The user does not have permission to perform this action.
--hello world
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
WHERE req.session_id = @@SPID
The documentation for sys.dm_exec_input_buffer states (emphasis mine):
On SQL Server, if the user has VIEW SERVER STATE permission, the user will see all executing sessions on the instance of SQL Server; otherwise, the user will see only the current session.
Thus, according to the documentation, I am allowed to access this data. Why, then, is the error being raised?
sql-server sql-server-2016 azure-sql-database
add a comment |
When I run this blob of SQL on SQL Server 2016 or an Azure SQL DB:
--hello world
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
WHERE req.session_id = @@SPID
I get this error, followed by the expected results:
Msg 300, Level 14, State 1, Line 5
VIEW SERVER STATE permission was denied on object 'server', database 'master'.
Msg 297, Level 16, State 1, Line 5
The user does not have permission to perform this action.
--hello world
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
WHERE req.session_id = @@SPID
The documentation for sys.dm_exec_input_buffer states (emphasis mine):
On SQL Server, if the user has VIEW SERVER STATE permission, the user will see all executing sessions on the instance of SQL Server; otherwise, the user will see only the current session.
Thus, according to the documentation, I am allowed to access this data. Why, then, is the error being raised?
sql-server sql-server-2016 azure-sql-database
When I run this blob of SQL on SQL Server 2016 or an Azure SQL DB:
--hello world
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
WHERE req.session_id = @@SPID
I get this error, followed by the expected results:
Msg 300, Level 14, State 1, Line 5
VIEW SERVER STATE permission was denied on object 'server', database 'master'.
Msg 297, Level 16, State 1, Line 5
The user does not have permission to perform this action.
--hello world
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
WHERE req.session_id = @@SPID
The documentation for sys.dm_exec_input_buffer states (emphasis mine):
On SQL Server, if the user has VIEW SERVER STATE permission, the user will see all executing sessions on the instance of SQL Server; otherwise, the user will see only the current session.
Thus, according to the documentation, I am allowed to access this data. Why, then, is the error being raised?
sql-server sql-server-2016 azure-sql-database
sql-server sql-server-2016 azure-sql-database
asked Sep 25 '18 at 18:00
TaudrisTaudris
1112
1112
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Using the condition WHERE req.session_id = <some value> triggers the error condition. Then the line is ignored, and the rest runs correctly. Try executing:
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
without the WHERE clause, and you should get the correct output.
tl;dr Looking for a specific session_id triggers the error.
Interesting line of thinking, but unfortunately, this didn't work. In SQL Server, I still get the behavior I described in my question. In Azure SQL DB,sys.dm_exec_requestsreturns more than just my session's requests (which contradicts the documentation), and I get an error for each row, including the one for my own session. It does not show me the input buffer for sessions other than my own when I useOUTER APPLY.
– Taudris
Sep 25 '18 at 21:48
add a comment |
Welcome, Taudris! My feeling is that it depends on what wackiness is is happening in SQL Azure, and how your permissions were set up, and how you are logged in. I have also noticed that if i run things when I am NOT in master, I don't get errors, but if i run them in the context of master, I do (even if I'm referring to a system view or function only available in master).
Additionally, if i connect using the sqllogin which is sa, I can run things which I cannot under my windows account which is supposed to have super rights, and vice versa.
It seems that setting up a DBA (at least at our company) with the appropriate limited but usable rights can be a challange. I actually didn't run into the issue you mentioned above, but I've run into other quirky behavior.
add a comment |
this does the same thing. Get the result but also a permission denied error
select event_info FROM sys.dm_exec_input_buffer(@@spid, NULL)
seems like a bug since the documentation says you should be able to view the info for the current spid. Should not get an error.
I found out the hard way. Put this in a proc to retrieve event_info. The proc ran and completed. The web client app got the error message.
New contributor
chris dickey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f218540%2fpermission-error-when-using-sys-dm-exec-input-buffer-with-spid%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Using the condition WHERE req.session_id = <some value> triggers the error condition. Then the line is ignored, and the rest runs correctly. Try executing:
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
without the WHERE clause, and you should get the correct output.
tl;dr Looking for a specific session_id triggers the error.
Interesting line of thinking, but unfortunately, this didn't work. In SQL Server, I still get the behavior I described in my question. In Azure SQL DB,sys.dm_exec_requestsreturns more than just my session's requests (which contradicts the documentation), and I get an error for each row, including the one for my own session. It does not show me the input buffer for sessions other than my own when I useOUTER APPLY.
– Taudris
Sep 25 '18 at 21:48
add a comment |
Using the condition WHERE req.session_id = <some value> triggers the error condition. Then the line is ignored, and the rest runs correctly. Try executing:
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
without the WHERE clause, and you should get the correct output.
tl;dr Looking for a specific session_id triggers the error.
Interesting line of thinking, but unfortunately, this didn't work. In SQL Server, I still get the behavior I described in my question. In Azure SQL DB,sys.dm_exec_requestsreturns more than just my session's requests (which contradicts the documentation), and I get an error for each row, including the one for my own session. It does not show me the input buffer for sessions other than my own when I useOUTER APPLY.
– Taudris
Sep 25 '18 at 21:48
add a comment |
Using the condition WHERE req.session_id = <some value> triggers the error condition. Then the line is ignored, and the rest runs correctly. Try executing:
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
without the WHERE clause, and you should get the correct output.
tl;dr Looking for a specific session_id triggers the error.
Using the condition WHERE req.session_id = <some value> triggers the error condition. Then the line is ignored, and the rest runs correctly. Try executing:
SELECT event_info
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)
without the WHERE clause, and you should get the correct output.
tl;dr Looking for a specific session_id triggers the error.
answered Sep 25 '18 at 21:12
Laughing VergilLaughing Vergil
848211
848211
Interesting line of thinking, but unfortunately, this didn't work. In SQL Server, I still get the behavior I described in my question. In Azure SQL DB,sys.dm_exec_requestsreturns more than just my session's requests (which contradicts the documentation), and I get an error for each row, including the one for my own session. It does not show me the input buffer for sessions other than my own when I useOUTER APPLY.
– Taudris
Sep 25 '18 at 21:48
add a comment |
Interesting line of thinking, but unfortunately, this didn't work. In SQL Server, I still get the behavior I described in my question. In Azure SQL DB,sys.dm_exec_requestsreturns more than just my session's requests (which contradicts the documentation), and I get an error for each row, including the one for my own session. It does not show me the input buffer for sessions other than my own when I useOUTER APPLY.
– Taudris
Sep 25 '18 at 21:48
Interesting line of thinking, but unfortunately, this didn't work. In SQL Server, I still get the behavior I described in my question. In Azure SQL DB,
sys.dm_exec_requests returns more than just my session's requests (which contradicts the documentation), and I get an error for each row, including the one for my own session. It does not show me the input buffer for sessions other than my own when I use OUTER APPLY.– Taudris
Sep 25 '18 at 21:48
Interesting line of thinking, but unfortunately, this didn't work. In SQL Server, I still get the behavior I described in my question. In Azure SQL DB,
sys.dm_exec_requests returns more than just my session's requests (which contradicts the documentation), and I get an error for each row, including the one for my own session. It does not show me the input buffer for sessions other than my own when I use OUTER APPLY.– Taudris
Sep 25 '18 at 21:48
add a comment |
Welcome, Taudris! My feeling is that it depends on what wackiness is is happening in SQL Azure, and how your permissions were set up, and how you are logged in. I have also noticed that if i run things when I am NOT in master, I don't get errors, but if i run them in the context of master, I do (even if I'm referring to a system view or function only available in master).
Additionally, if i connect using the sqllogin which is sa, I can run things which I cannot under my windows account which is supposed to have super rights, and vice versa.
It seems that setting up a DBA (at least at our company) with the appropriate limited but usable rights can be a challange. I actually didn't run into the issue you mentioned above, but I've run into other quirky behavior.
add a comment |
Welcome, Taudris! My feeling is that it depends on what wackiness is is happening in SQL Azure, and how your permissions were set up, and how you are logged in. I have also noticed that if i run things when I am NOT in master, I don't get errors, but if i run them in the context of master, I do (even if I'm referring to a system view or function only available in master).
Additionally, if i connect using the sqllogin which is sa, I can run things which I cannot under my windows account which is supposed to have super rights, and vice versa.
It seems that setting up a DBA (at least at our company) with the appropriate limited but usable rights can be a challange. I actually didn't run into the issue you mentioned above, but I've run into other quirky behavior.
add a comment |
Welcome, Taudris! My feeling is that it depends on what wackiness is is happening in SQL Azure, and how your permissions were set up, and how you are logged in. I have also noticed that if i run things when I am NOT in master, I don't get errors, but if i run them in the context of master, I do (even if I'm referring to a system view or function only available in master).
Additionally, if i connect using the sqllogin which is sa, I can run things which I cannot under my windows account which is supposed to have super rights, and vice versa.
It seems that setting up a DBA (at least at our company) with the appropriate limited but usable rights can be a challange. I actually didn't run into the issue you mentioned above, but I've run into other quirky behavior.
Welcome, Taudris! My feeling is that it depends on what wackiness is is happening in SQL Azure, and how your permissions were set up, and how you are logged in. I have also noticed that if i run things when I am NOT in master, I don't get errors, but if i run them in the context of master, I do (even if I'm referring to a system view or function only available in master).
Additionally, if i connect using the sqllogin which is sa, I can run things which I cannot under my windows account which is supposed to have super rights, and vice versa.
It seems that setting up a DBA (at least at our company) with the appropriate limited but usable rights can be a challange. I actually didn't run into the issue you mentioned above, but I've run into other quirky behavior.
answered Sep 26 '18 at 13:38
rottengeekrottengeek
590416
590416
add a comment |
add a comment |
this does the same thing. Get the result but also a permission denied error
select event_info FROM sys.dm_exec_input_buffer(@@spid, NULL)
seems like a bug since the documentation says you should be able to view the info for the current spid. Should not get an error.
I found out the hard way. Put this in a proc to retrieve event_info. The proc ran and completed. The web client app got the error message.
New contributor
chris dickey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
this does the same thing. Get the result but also a permission denied error
select event_info FROM sys.dm_exec_input_buffer(@@spid, NULL)
seems like a bug since the documentation says you should be able to view the info for the current spid. Should not get an error.
I found out the hard way. Put this in a proc to retrieve event_info. The proc ran and completed. The web client app got the error message.
New contributor
chris dickey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
this does the same thing. Get the result but also a permission denied error
select event_info FROM sys.dm_exec_input_buffer(@@spid, NULL)
seems like a bug since the documentation says you should be able to view the info for the current spid. Should not get an error.
I found out the hard way. Put this in a proc to retrieve event_info. The proc ran and completed. The web client app got the error message.
New contributor
chris dickey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
this does the same thing. Get the result but also a permission denied error
select event_info FROM sys.dm_exec_input_buffer(@@spid, NULL)
seems like a bug since the documentation says you should be able to view the info for the current spid. Should not get an error.
I found out the hard way. Put this in a proc to retrieve event_info. The proc ran and completed. The web client app got the error message.
New contributor
chris dickey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
chris dickey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 1 min ago
chris dickeychris dickey
1
1
New contributor
chris dickey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
chris dickey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
chris dickey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f218540%2fpermission-error-when-using-sys-dm-exec-input-buffer-with-spid%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown