I'm attempting to run the default "Welcome to ASP.NET MVC!" MVC3 application on Azure, using SQL Azure for the ASP.NET membership store, via ASP.NET Universal Providers. I have a SQL Azure database called "MyDatabase" with a new login and user both called "MyUser". The user is tied to the login and has been given the dbo_owner role for MyDatabase. MyDatabase is set as a linked resource to the web role in the management portal.
The site shows up fine on Azure, but trying any database operation, my database connection fails:
Cannot open database "master" requested by the login. The login failed. Login failed for user 'MyUser'.
Searching for answers, the usual response is to set the "Database" parameter in the connection string. I have indeed done this, but it still keeps trying "master." It's like it's being ignored:
Server=tcp:myserver.database.windows.net,1433;Database=MyDatabase;User ID=MyUser@myserver;Password=mypassword;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True
Other things I've ruled out:
Probably some newbie mistake here - what else should I check?
A look into the stack trace of the exception helped solve this one:
... at System.Data.SqlClient.SqlProviderServices.UsingMasterConnection(...) at System.Data.SqlClient.SqlProviderServices.DbDatabaseExists(...) at System.Data.Objects.ObjectContext.DatabaseExists() at System.Web.Providers.Entities.DatabaseCreationHelper.DatabaseExists(...) at System.Web.Providers.ModelHelper.CreateMembershipEntities(ConnectionStringSettings setting) at System.Web.Providers.DefaultMembershipProvider.Membership_CreateUser(...) ...
Since I was using a new database, the ASP.NET Universal Providers were trying to create the membership/role tables, and for some reason did actually need to use the master database to accomplish this. I added a new user to master, tied to my login, and made sure it had the "dbmanager" role so that it could create tables if needed.
I'm not 100% sure why it needs to go through master, but the stack trace makes it looks like it does so to check if the database you give it actually exists. (Please go ahead and comment if you know the definitive answer!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With