Check if Windows User is an SQL Admin

  • I'm building an application where it is asking the user for SQL Credentials to make Schema Updates. The credentials can be either and SQL User & Password or Trusted Connection (ie the currently logged on windows user).

    Now, if the user uses Trusted Connection, the application created a connection string and connects. But how can it be sure that the user is an SQL Admin before the Schema Update starts?

    Thanks

    JP

  • IS_MEMBER function checks whether the current user is a member of the specified windows or sql database role. And to check specifically for object level permissions, see PERMISSIONS function.

    --Ramesh


  • Thanks

    Although it's not exactly what I needed, I found the Function Is_SrvRoleMember('SysAdmin') from it's help page.

    JP

  • JP-1019544 (2/18/2009)


    Thanks

    Although it's not exactly what I needed, I found the Function Is_SrvRoleMember('SysAdmin') from it's help page.

    JP

    Your answer might not be correct as mentioned here -

  • Testing for sysadmin is not really the right thing to do in this case. Best practice is to use the lowest possible permissions needed to complete a task.

    The permission needed is ALTER ANY CREDENTIAL and you should test for this. It is possible to grant this permission to any user, so you do not need to be a Sysadmin in order to create a credential.

    Original author: https://github.com/SQL-FineBuild/Common/wiki/ 1-click install and best practice configuration of SQL Server 2019, 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005.

    When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist - Archbishop Hélder Câmara

  • My feeling is that if an application has any more than (at the most) read/write privs, then the application is incorrectly written. The application should be calling on prived stored procedures to do the job safely.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • The application should be calling on prived stored procedures to do the job safely.

    +1

    Original author: https://github.com/SQL-FineBuild/Common/wiki/ 1-click install and best practice configuration of SQL Server 2019, 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005.

    When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist - Archbishop Hélder Câmara

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply