Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New user cannot login to SQL Azure

I am creating a new read/write user on SQL Azure as follows:

-- Connected to master create login [fred] with password = 'xxx';  -- Connected to my DB create user [fred] from login fred; EXEC sp_addrolemember 'db_datareader', 'fred'; EXEC sp_addrolemember 'db_datawriter', 'fred'; 

When I login using SSMS I get an error saying Cannot open database "master" requested by the login. The login failed.

What am I doing wrong or missing?

like image 856
Sean Kearon Avatar asked Jun 25 '11 08:06

Sean Kearon


People also ask

Can't connect to SQL Server on Azure?

Steps to resolve persistent connectivity issuesSet up firewall rules to allow the client IP address. On all firewalls between the client and the Internet, make sure that port 1433 is open for outbound connections. Review Configure the Windows Firewall to Allow SQL Server Access for additional pointers.

How do I create a new user in a SQL Azure database?

Connect to your Azure SQL Database server with SSMS as an admin and choose the database you want to add a user to in the dropdown. Add Azure Active Directory user '[email protected]' then add it to the db_datareader and db_datawriter roles.


2 Answers

By default, SSMS tries to connect to master, but your new account does not have access to master; only the user database I presume.

On the login screen of SSMS, you need to specify the database name as well; just click on the Options >> icon, which opens up the Connection Properties tab. In there, specify the database name you are trying to connect to.

like image 153
Herve Roggero Avatar answered Sep 19 '22 22:09

Herve Roggero


After creating the database user in the specific database Database1, again select 'master' and create database user. Execute below statement twice - one for Database1 and another for 'master'

CREATE USER appuser1 FROM LOGIN appuser1; 

Unfortunately, this is not documented in Azure help https://docs.microsoft.com/en-gb/azure/azure-sql/database/logins-create-manage

like image 40
Jyo Reddy Avatar answered Sep 21 '22 22:09

Jyo Reddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!