Question

I'm stuck with this "dreadful" error message trying to deploy an MVC web site on Azure :

Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.

DataBase First Workflow was used from scratch (adding ADO.Net Entity Data Model element and following wizzard connecting to an Azure SQL Server DB). So I can't figure out why it's besetting me with Code First. Using EF 6.0 with T4 templates. Generated DbContext looks like this :

    public partial class MyAppEntities : DbContext
    {
        public MyAppEntities()
            : base("name=MyAppEntities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public virtual DbSet<AType> AType { get; set; }
        public virtual DbSet<BType> BType { get; set; }
        // etc.
    }

Connection string looks like this. Copied both in DAL project and StartUp project web config :

<add name="MyAppEntities" connectionString="metadata=res://*/MyAppModel.csdl|res://*/MyAppModel.ssdl|res://*/MyAppModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=ndkkyxvogj.database.windows.net;initial catalog=DbName;persist security info=True;user id=myuserid;password=Pa$$word;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

App runs without any problem on local machine.

Deploying process on Azure follow these steps.

  • Create (custom creation) web site on Azure and give db credentials

  • Download publish profile from Azure dash board

  • In VS click Publish from start up project and set following parameters :

  • -> Profile : Import downloaded profile
  • -> Connection : Connection well set and validates
  • -> Settings : Not sure at all what is awaited here !!! I tryed both connection settings : With suggested connection strings and with EDMX connection string. like this :

    metadata=res:///MyAppModel.csdl|res:///MyAppModel.ssdl|res://*/MyAppModel.msl;provider=System.Data.SqlClient;provider connection string="data source=ndkkyxvogj.database.windows.net;initial catalog=MyDb;persist security info=True;user id=databaseuser;password=Pa$$word;MultipleActiveResultSets=True;App=EntityFramework"

Tryed to comment OnModelCreating(). Didn't work. Also tryed to comment throw on UnintentionalCodeFirstException(). Didn't work either.

Despite research on other SO Q & A, couldn't find any reliable solution. Any help would be greatly appreciated.

Was it helpful?

Solution

Ok got it ...

Actually, falling on that post and that one, it appears that it is Azure misleading between the connection string names both given the same in Azure Sql Server and the Azure Web Site.

It has nothing to do with a whatsoever bad EF implementation between code first/model first or db first ...

So I gave connection string name a new one in the web App config, Context Class constructor, and in the azure web sites connection string name parameters ... And it worked.

It was a real pain figuring this out ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top