Monday, 09 March 2015
How to change the database for Entity Framework to Azure Database
This article was published at GitHub. It is open source and you can make edits, comments etc.
I spent a little time trying to change the database that Entity Framework uses so that I could developer against an Azure database rather than the local default one. It is fairly simple, but took me a while to figure out so I thought I'd capture it....
By default, Visual Studio creates an MDF file in the 'app_data' folder in your project; this is where Entity Framework stores the data that gets generated from your application. The MDF file will be named after the data context you created when you first setup your project or controller, if you followed all the default suggestions, it will be something like 'WebApplication1Context-[datestamp].mdf'. If you double click this file (it is hidden so you'll have to 'show all files'), you'll be able to explore the database.
I quite often need to change the location of the database to something that is not on my machine such as an Azure Database. This is very easy to do, simply open your Web.Config, under Configuration > ConnectionStrings you'll find an entry that is named after your data context ('WebApplication1Context' by default) and change the 'connectionString' value of this to be whatever you need.
I personally like to use an Azure database because I know I can get to it from anywhere.
It is very easy to get the connection string for an Azure database, follow these steps:
If you are using an azure database, you'll also need to configure azure to allow access from your PC, to do this, follow these steps:
There are lots of reason why you might need to do this, here are just a few:
Got a comment?
All my articles are written and managed as Markdown files on GitHub.
Please add an issue or submit a pull request if something is not right on this article or you have a comment.
If you'd like to simply say "thanks", then please send me a .