How To Create Users To Connect To An Azure SQL Server Database



 TODO:

 Have you ever wanted to connect to a SQL Azure Database from .Net and get a Access Denied error?  The issue is you need to create a user to use in your connection strings.

 

SOLUTION:

--run on master DB
CREATE LOGIN myuser WITH password='mypassword';

--run on Application DB
CREATE USER myuser FROM LOGIN myuser;
exec sp_addrolemember db_datareader, myuser 
go
exec sp_addrolemember db_datawriter, myuser

 

NOTES:

You cannot use the 'use' keyword, so  you need to open a new query window for each database.  Once complete, use this user / pass in your code and you can connect to the DB.



Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading