Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Mobile Service login error with database and "master" user

I've been using Azure Mobile Services with my apps without much issue, but then today when I tried to pull from the service I get this error:

Exception=System.Data.SqlClient.SqlException (0x80131904): Cannot open database "master" requested by the login. The login failed. Login failed for user 'JVlSvKwDpdLogin_*****'.

I've never had this issue come up before, and I'm only connecting to my mobile service in code like this:

public static MobileServiceClient MobileService = new MobileServiceClient(
        "https://<webservicename>.azure-mobile.net/",
        "<YOUR-API-KEY-HERE>"
    );

Before this error happened, I never supplied a username or password. I've seen some solutions where they've created a user for the database but I don't want to create one right now since we're still in testing and I'd rather be able to use the service without one for now. Is this an issue with mobile service, or an issue with the database?

UPDATE

As suggested by Matt's answer below, I found the MS_ConnectionString in the Azure portal. I then connected to the 'master' database on my Azure SQL server and searched for the login above. I changed the password to the one found in the connection string using

ALTER LOGIN <login> WITH password='<password-found-in-connection-string>';

But now I get this error:

Exception=System.Data.Entity.Core.ProviderIncompatibleException: An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure. ---> System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.Data.SqlClient.SqlException: Login failed for user 'JVlSvKwDpdLogin_*******'.

I haven't change anything with the connection string or the web.config file for my AzureMobileService project.

web.config:

<connectionStrings>
<add name="MS_TableConnectionString" connectionString="Data Source=    (localdb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-CoverageTool.AzureMobileService-20140910083006.mdf;Initial Catalog=aspnet-CoverageTool.AzureMobileService-20140910083006;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>

MobileContext:

private const string connectionStringName = "Name=MS_TableConnectionString";

    public MobileServiceContext()
        : base(connectionStringName)
    {
    }

Connection String

Data Source=*****.database.windows.net;Initial Catalog=sbpconsulting_db;User ID=*******Login_sbpconsulting;Password=**************;Asynchronous Processing=True;TrustServerCertificate=False;

like image 263
Ebsan Avatar asked Sep 16 '14 01:09

Ebsan


2 Answers

This error could also appear if your Entity Framework database initializers are not compatible with the permissions of the database user that your Azure Mobile Service is using.

For example, when you create database for a Azure Mobile Service, Azure automatically creates a DB user for your service. This user does not have admin permissions - it can generally read and write data to a table. In that case, if you are using DropCreateDatabaseAlways DB initializer your user will not have sufficient permission to actually drop the database and you may see the error that you have mentioned.

There are new initializers that were introduced to work with limited set of permissions:

  • ClearDatabaseSchemaAlways - use instead of DropCreateDatabaseAlways
  • ClearDatabaseSchemaIfModelChanges - use instead of DropCreateDatabaseIfModelChanges
like image 135
Milan Nankov Avatar answered Nov 15 '22 00:11

Milan Nankov


I can only think of one thing that may be the problem. Windows Azure Databases only allow specific ip addresses that you have white listed before hand.

So if you are trying to run your app from a different internet connection or if your ip address has changed then that might be your issue.

Try accessing your database directly on your Azure Management Console and allow your ip address access to the database server.

Azure always needs authentication so check your applications app.config / web.config file for credentials.

More code-based information would have been helpful to make this answer more than a shot in the dark.

like image 45
Thamsanqa Bengu Avatar answered Nov 14 '22 22:11

Thamsanqa Bengu