0
votes

I've built a simple Web API that I'm hosting at Azure, it's modelled on the Get started with Mobile Services iOS .NET backend sample application:

http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-ios-get-started/

For the purposes of getting the sample closer to something useful for me I've changed the

\DataObjects\ToDoItem.cs

Model to an alternative series of int/string types.

I'm using: Entity Framework 6.1.0, Visual Studio 2013.

However whenever I deploy through the "right click on project" -> Publish Web wizard and then try to access the Web API via a valid HTTP REST call I get the following 500 HTTP Error thrown at Azure.

Exception=System.NotSupportedException: Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations...

If I, through the Visual Studio Package Manager Console locally, use:

Enable-Migrations

And play about with "Add-Migration " and "Update-Database"

I can alternatively throw this error @ Azure ("<" and ">" markers below contain my description):

Exception=System.InvalidOperationException: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection. ---> System.Data.SqlClient.SqlException: Login failed for user '<10 Alpha Character (upper and lower case) - seems to be random, not a DB name or server as far as I can tell>Login_'.

I've also connected to the Azure DB cloud in SQL Management Studio, there's no Tables in the associated DBs to the Mobile Service applications.

Help would very much be appreciated in getting this sorted. Thanks.

1

1 Answers

1
votes

Sorted.

The root of the problem was a poor understanding of Entity Framework as to how it wires the Model to EntityContext.MyContext

I found the following article to be a very useful resource in fixing the issue, critical for this issue to me was the explanation of the Context implementation:

Article: http://blogs.msdn.com/b/azuremobile/archive/2014/04/10/creating-an-azure-mobile-services-net-backend-from-scratch.aspx

Code sample:

public class MyContext : EntityContext
{
    public MyContext()
        : base()
    {
    }

    public MyContext(string schema)
        : base(schema)
    {
    }

    public DbSet<TodoItem> TodoItems { get; set; }
}