Home Forums SQL Server 2008 T-SQL (SS2K8) Trying to build a stored procedure with insert into... RE: Trying to build a stored procedure with insert into...

  • Okay, my bad, now I see where the problem is. It seems like it's centered around the "WITH EXECUTE AS ___" part.

    The problem is easy to identify - just change the procedure to become "SELECT * FROM sys.databases", if you remove the WITH EXECUTE AS, you'll see all the databases, but if you keep it, you will only see a subset.

    Take a look at this article on MSDN:

    http://technet.microsoft.com/en-us/library/ms178534.aspx

    Specifically, this part:

    "If the caller of sys.databases is not the owner of the database and the database is not master or tempdb, the minimum permissions required to see the corresponding row are ALTER ANY DATABASE or VIEW ANY DATABASE server-level permission, or CREATE DATABASE permission in the master database. The database to which the caller is connected can always be viewed in sys.databases."

    Take a look at this thread:

    https://groups.google.com/forum/#!topic/microsoft.public.sqlserver.security/GO5CBzHZ4vY

    See the responses given by Erland Sommarskog. Hopefully they should answer your questions.