1

I have successfully created a login for a user on our Azure SQL DB using the following code:

CREATE LOGIN [xxxxxxxx] WITH PASSWORD=N'4QfaE+AV0TdFBpiP/ZnqCg/clPPwEeT2ZfZzDEdM2k8='

However, when I attempt to access the database with the login I get the error

The server principal "xxxxxxxxxxxxxx" is not able to access the database "xxxxxxx" under the current security context.
Cannot open database "axxxxxxx" requested by the login. The login failed.
Login failed for user 'xxxxxxxxxxx'.

I guess the problem is that I need to give the user permissions to access the database. Give someone snow me how to give full access to the user for the database please.

I am using SSMS 20.2

Paul White
95.3k30 gold badges439 silver badges689 bronze badges
asked Dec 14, 2024 at 18:58

2 Answers 2

3

FWIW, another option is to not create a login in the first place. Skip the login part and just create a user with a password. Since this is SQL Database, containment is enabled, meaning no knob need to be set in order to allow this.

Since we can't USE database in SQL Db anyhow, the connections string need to have the database on it so there shouldn't be any functional disadvantage. (Unless you want to have the same login name and password for other databases on that same logical server, of course.)

CREATE USER CarmenW WITH PASSWORD = 'a8ea v*(Rd##+' 
answered Dec 16, 2024 at 10:34
2

Create a database user for the login. Connected to the target database run

CREATE USER <UserName> FOR LOGIN <LoginName>

Then grant the user whatever database permissions you need. Eg:

GRANT SELECT TO <UserName>

or

GRANT CONTROL TO <UserName>
answered Dec 14, 2024 at 20:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.