Reputation: 539
I'm having trouble publishing my Entity Framework database to azure.
I'm working with .NET framework 4.5 and EF 6.1.3. The way my project is set up is as follows and using a code first approach:
My web services project has references to the repository library and the DTOs library and I never created the database explicitly because EF created it for me using SQL server express I believe, I set up the web.config as follows:
<connectionStrings>
<add name="Database" connectionString="Server=(localdb)\v11.0;Database=Database;Trusted_Connection=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
In my project the database is created along with all the tables and relationships. I added some initial migrations in the repository library like this
namespace Project.Repository.Migrations
{
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<Project.Repository.ProjectContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}
protected override void Seed(Project.Repository.ProjectContext context)
{
Guid userId = new Guid();
Guid restaurantId = new Guid();
context.Users.AddOrUpdate(
u => u.Id, new Domain.Security.User { Id = userId, Age = 18, Description = "I like restaurants", Email = "[email protected]", Password = "12345", Username = "someuser" }
);
context.Restaurants.AddOrUpdate(
r => r.Id,
new Domain.Restaurants.Restaurant
{
Id = restaurantId,
Name = "mcdonalds",
Description = "best restaurant",
FacebookUrl = "www.facebook.com",
GoogleUrl = "www.google.com",
InstagramUrl = "www.instagram.com",
TwitterUrl = "www.twitter.com",
Votes = 3.5f,
UsersWhoLike = new List<Domain.Security.User>() { context.Users.FirstOrDefault(u => u.Id == userId) }
}
);
context.SaveChanges();
}
}
}
When I set to publish the project to my azure websites the webservices publish allright but the database doesn't or at least whenever I call the restaurants service with website/api/restaurants which is the route for getting a list of restaurants it says.
{"Message":"An error has occurred."}
My azure database connection string is setup like this:
Data Source=tcp:someidentifier.database.windows.net,1433;Initial Catalog=Database;Integrated Security=False;User ID=Database@someidentifier;Password=xxxxxx;Connect Timeout=30;Encrypt=True
I don't know what is happening and I don't know if azure is actually seeding the database, what did I left out or what could be my mistakes?
Upvotes: 1
Views: 1790
Reputation: 11
To can see exceptions in azure portal go to your web app -> Tools -> Troubleshoot -> Live HTTP traffic, select Analyze.
Upvotes: 1
Reputation: 6531
First of all, go to your asp.net webconfig and set this value to Off:
<system.web><customErrors mode="Off"/></system.web>
You'll get an informative Yellow Screen of Death and have a chance of figuring out what's actually wrong. If the YoD is unclear, post it on your answer.
Upvotes: 1