Share via

User can't access db under current security context

Eric L 0 Reputation points
2025-03-23T20:14:30.57+00:00

I am receiving the following error when attempting to connect to a database that I just created yesterday, however clearly there is some default setting for security that is blocking my access. I have no idea how to resolve this issue. Can someone help?

WHY IS THE AI BASED TOOL MARKING MY CONTENT AS AGAINST CODE OF CONDUCT BECAUSE I PASTED THE EXACT CONTENT OF THE ERROR MESSAGE?

Azure SQL Database

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 41,721 Reputation points MVP Volunteer Moderator
    2025-03-23T21:11:08.9966667+00:00

    Hello Eric !

    Thank you for posting on Microsoft Learn.

    Did you create the Azure SQL Server yourself? If so, the login you created during provisioning should be the server admin.

    If you're using Azure Active Directory (AAD) for login, ensure your user is properly added to the database with correct roles (db_owner...).

    If you are the server admin, connect to the master database and run this to grant yourself access to the new DB:

    CREATE USER [your_user] FROM LOGIN [your_user];
    
    ALTER ROLE db_owner ADD MEMBER [your_user];
    
    

    Or, switch to the target database and run:

    CREATE USER [your_user] FROM LOGIN [your_user];  
    
    ALTER ROLE db_owner ADD MEMBER [your_user];
    
    

    If you're using AAD:

    CREATE USER [******@domain.com] FROM EXTERNAL PROVIDER;
    
    ALTER ROLE db_datareader ADD MEMBER [******@domain.com];
    
    ALTER ROLE db_datawriter ADD MEMBER [******@domain.com];
    
    

    If you want to verify with the Azure Portal, go to your Azure SQL server resource > Active Directory admin and check if your account is set as admin.

    You can also check SQL users and permissions from the Azure Portal (under the database > Query editor (preview)) if you can log in there.

    Was this answer helpful?


Your answer

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