UnintentionalCodeFirstException on remote server (Azure)

BrunoLM

I built a website that is working perfectly locally. Then I tried to deploy to Azure. Everything that doesn't use a database works fine, but when I try to access the database I get:

System.Data.Entity.Infrastructure.UnintentionalCodeFirstException:
Code generated using the T4 templates for Database First and Model First
development may not work correctly if used in Code First mode...

   at MySite.Infrastructure.DatabaseContainer.OnModelCreating(DbModelBuilder modelBuilder)
   at System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder()
   at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
   at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
   at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
   at System.Data.Entity.DbSet`1.Add(TEntity entity)
   at MySite.Services.ServiceBase`1.Add(T o)
   at MySite.Controllers.SomeController.New(SomeObject objectParam)

My local connection string is

<add name="DatabaseContainer" connectionString="metadata=res://MySite.Data/Database.csdl|res://MySite.Data/Database.ssdl|res://MySite.Data/Database.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\sqlexpress;initial catalog=MyDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

My remote connection string is

<add name="DatabaseContainer" connectionString="metadata=res://MySite.Data/Database.csdl|res://MySite.Data/Database.ssdl|res://MySite.Data/Database.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=serverstuff.from.azure;Initial Catalog=MyDatabase;User Id=MyUser;Password=MyPassword;App=EntityFramework&quot;" providerName="System.Data.EntityClient"
  xdt:Transform="SetAttributes" xdt:Locator="Match(name)"
/>

My DbContext class

//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace MySite.Infrastructure
{

    using MySite.Models;

    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

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

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

        public DbSet<SomeObject> SomeObjects { get; set; }
    }
}

MySite.Services.ServiceBase`1.Add(T o) is just

db.SomeObjects.Add(o);
db.SaveChanges();

I checked Azure, the database is created and there is a table "SomeObject".

I do not understand the reason why it is trying to execute OnModelCreating. Locally it works just fine.

What could be causing this?

BrunoLM

Just found out that I had a ConnectionString with the same name on Azure panel, which was overriding my configuration in Web.Config.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

UnintentionalCodeFirstException on remote server (Azure)

From Dev

Azure Web Job-The remote server returned 404

From Dev

npm -g install weinre on windows azure remote server

From Dev

Azure "The remote server returned an error: (530) Not logged in."

From Dev

How to connect to a remote MySQL from an Azure SQL server/database

From Dev

Azure "The remote server returned an error: (530) Not logged in."

From Dev

SCP from remote server to another remote server

From Dev

Transfer a file from remote server to remote server

From Dev

Transfer a file from remote server to remote server

From Dev

SCP from remote server to another remote server

From Dev

Cannot upload to azure Blob Storage: The remote server returned an error: (400) Bad Request

From Dev

Windows Azure Storage version upgrade to > 4 causes "The remote server returned an error: (400) Bad Request."

From Dev

How connect to Microsoft Azure (MSA) Windows Server (WIN) with Remote Desktop (RDP) in Linux

From Dev

Azure Notification Service: The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:

From Dev

Enabling Azure Remote Desktop

From Dev

Terraform remote state azure

From Dev

remote powershell in azure VM

From Dev

Server.MapPath on a remote server

From Dev

Connect LINQPad to Remote Server

From Dev

TcpClient not connecting to remote server

From Dev

Server, Remote Login, SSH?

From Dev

Mongodump from remote server

From Dev

Simple remote server with django

From Dev

MySQL server remote connection?

From Dev

Run Eclim on the remote server

From Dev

Remote server not found in XMPP

From Dev

Subprocess on remote server

From Dev

Robot Framework Remote Server

From Dev

Weather API on remote server

Related Related

  1. 1

    UnintentionalCodeFirstException on remote server (Azure)

  2. 2

    Azure Web Job-The remote server returned 404

  3. 3

    npm -g install weinre on windows azure remote server

  4. 4

    Azure "The remote server returned an error: (530) Not logged in."

  5. 5

    How to connect to a remote MySQL from an Azure SQL server/database

  6. 6

    Azure "The remote server returned an error: (530) Not logged in."

  7. 7

    SCP from remote server to another remote server

  8. 8

    Transfer a file from remote server to remote server

  9. 9

    Transfer a file from remote server to remote server

  10. 10

    SCP from remote server to another remote server

  11. 11

    Cannot upload to azure Blob Storage: The remote server returned an error: (400) Bad Request

  12. 12

    Windows Azure Storage version upgrade to > 4 causes "The remote server returned an error: (400) Bad Request."

  13. 13

    How connect to Microsoft Azure (MSA) Windows Server (WIN) with Remote Desktop (RDP) in Linux

  14. 14

    Azure Notification Service: The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:

  15. 15

    Enabling Azure Remote Desktop

  16. 16

    Terraform remote state azure

  17. 17

    remote powershell in azure VM

  18. 18

    Server.MapPath on a remote server

  19. 19

    Connect LINQPad to Remote Server

  20. 20

    TcpClient not connecting to remote server

  21. 21

    Server, Remote Login, SSH?

  22. 22

    Mongodump from remote server

  23. 23

    Simple remote server with django

  24. 24

    MySQL server remote connection?

  25. 25

    Run Eclim on the remote server

  26. 26

    Remote server not found in XMPP

  27. 27

    Subprocess on remote server

  28. 28

    Robot Framework Remote Server

  29. 29

    Weather API on remote server

HotTag

Archive