SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

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

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.

Filed under: Microsoft SQL Server, Problem Resolution, SQLServerPedia Syndication, T-SQL Tagged: microsoft sql server, problem resolution, T-SQL


My name is Kenneth Fisher and I am Senior DBA for a large (multi-national) insurance company. I have been working with databases for over 20 years starting with Clarion and Foxpro. I’ve been working with SQL Server for 12 years but have only really started “studying” the subject for the last 3. I don’t have any real "specialities" but I enjoy trouble shooting and teaching. Thus far I’ve earned by MCITP Database Administrator 2008, MCTS Database Administrator 2005, and MCTS Database Developer 2008. I’m currently studying for my MCITP Database Developer 2008 and should start in on the 2012 exams next year. My blog is at www.sqlstudies.com.


Leave a comment on the original post [sqlstudies.com, opens in a new window]

Loading comments...