Select permission 2

Hram Admin 80 Reputation points
2025-03-04T08:40:36.6933333+00:00

Hello!

Please excuse me for almost the same question as "Select permission" but there's one thing I'd like to be cleared up:

I see that I can't query a user database (at least the databases for which the Guest account is disabled) until the user mapping between an sql login and a db user is created...

Q1

...but what I still do not understand is why does the fn_my_permissions function applied to a user db (Resources) does show SELECT permission for the user (Contoso1\exchadmin) which has NOT YET been mapped to???

Q2

use msdb
go
EXECUTE AS USER = 'Contoso1\exchadmin' 
select Name, physical_name, state_desc, (size)*8/1024, growth from msdb.sys.database_files ORDER BY Name
select Name, physical_name, state_desc, (size)*8/1024, growth from Resources.sys.database_files ORDER BY Name
SELECT * FROM fn_my_permissions('msdb.sys.database_files', 'object')
SELECT * FROM fn_my_permissions('Resources.sys.database_files', 'object')
Revert


Thank you in advance,
Michael

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
147 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 118.9K Reputation points MVP
    2025-03-04T22:32:59.2466667+00:00

    I guess this is because names in the sys schema resolves to the resource database. (That is, mssqlsystemresource, not the one you call resource!)

    I tried this:

    CREATE LOGIN Villevalle WITH PASSWORD = 'LÄÖÄF"?=='
    EXECUTE AS LOGIN = 'Villevalle'
    go
    SELECT * FROM sys.fn_my_permissions('somedatabase.sys.tables', 'OBJECT')
    SELECT * FROM sys.fn_my_permissions('somedatabase.dbo.sometable', 'OBJECT')
    go
    REVERT
    DROP LOGIN Villevalle
    

    The first SELECt did indeed return a row with SELECT permission. But the other query produced an error message:

    Msg 916, Level 14, State 2, Line 89 The server principal "Villevalle" is not able to access the database "somedatabase" under the current security context.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.