Entity framework, code first : Avoid unwanted connections to the azure master database Entity framework, code first : Avoid unwanted connections to the azure master database azure azure

Entity framework, code first : Avoid unwanted connections to the azure master database


Entity Framework is trying to connect to the master database because Code First attempts to create the database for the project if it doesn't exist. This can only be done from master.

You can still use Code First and work against an existing database, but you need to change the settings at least so it won't try to create the database. You can set it for updates, that's fine. My personal preference is to turn all database management off, and handle it myself.

This is done by creating a static overload constructor on your DbContext:

public static MyContext() : base(null) {}

This link discusses the different database initializers that are available. The above static constructor creates no initializer. Here is another link that discusses the same initializers, as well as creating custom ones.