sp_refreshsqlmodule_internal – The user does not have permission to perform this action.

Leave a comment

December 28, 2016 by Kenneth Fisher

Honestly, I’m only posting this because I had a hard time finding anything posted on this error and I found it somewhat unclear. Here is a quick walk through to produce the error:

-- Create server principal.
-- Create a database principal with read only access.
USE Test;
EXEC sp_addrolemember 'db_datareader','SQLTest';
-- Create a view.
CREATE VIEW dbo.ViewToRefresh
SELECT * FROM sys.databases;

Then login in as SQLTest and run this code:

-- Attempt to refresh the view.
USE Test;
EXEC sp_refreshview 'dbo.ViewToRefresh';

Msg 297, Level 16, State 3, Procedure sp_refreshsqlmodule_internal, Line 74 [Batch Start Line 2]
The user does not have permission to perform this action.

First, if you aren’t aware of what sp_refreshview is you can read a bit more about it here. But basically it’s exactly what it sounds like. It refreshes the view definition.

So what’s up with the error? Well sp_refreshsqlmodule_internal is an undocumented system procedure called by the system procedure sp_refreshsqlmodule which is called by sp_refreshview. You aren’t going to find it in any of the system databases. We just aren’t allowed to see it. Which is singularly unhelpful in trying to track down what’s going on.

Interestingly if SQLTest doesn’t even have read access to the view we get a bit more helpful error.

Msg 15165, Level 16, State 1, Procedure sp_refreshsqlmodule_internal, Line 62 [Batch Start Line 3]
Could not find object ‘dbo.ViewToRefresh’ or you do not have permission.

So how do we fix this? Well, the least permissions fix is to give the database principal alter on the view being refreshed.

GRANT ALTER ON dbo.ViewToRefresh TO SQLTest;

And the refresh will now work with or without read or write access.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 3,753 other subscribers

Follow me on Twitter

ToadWorld Pro of the Month November 2013
%d bloggers like this: