Entity Framework Code First with AWS SQL RDS

In this article I’m going to take you through the steps for using Amazon RDS with Entity Framework code first. I will not be covering any details related to Entity Framework. First you need to install AWS Tools for .NET. Then you will need to open up the AWS explorer from visual Studio View menu. Remember you need to have your account setup with Amazon Web Services. From this you can manipulate your AWS account.


So first I am going to create a database using the AWS RDS. Here I will be selecting the Amazon RDS (Relational Database Services).


Right click on the DB Instance under Amazon RDS and select Launch DB Instance.


Select the DB instance you want. Here I will be selecting the MS SQL Server Express Edition.


Select next. On this screen provide the instance information.


Click next. On the next screen you can provide additional information such as port number, availability zone, etc. Make sure that you check on “Add current CIDR….” Check box to allow the aws firewall access so that your local connections will go through.


I will be leaving the default settings on this page as this is just a demo. You can change the settings based on your requirements.


You can view the instance details before starting on the next screen.


Click Launch. This will take few minutes to launch the instance.


I have already created a sample MVC 4 application which uses Entity Framework code first. As you can see the solution is layered into two sections. The data model and the web. On the web layer I have named the context as “SystemDBContext”.


Also I have created some sample data as well. So during the database creation the database will have sample data. Also you can use this to have the default data loaded as well.


Now the database is ready and ready to go.


Next you need to set the connection string as given bellow on your web.config file.


Now you are ready to roll out. Open the Package Manager console and type the given command.


As you can see when we use ‘-Verbose’ it will show the execution summary on the console.


At the end it will execute the seed method to populate the database with sample data or default data. So every time you drop and create databases you will always have some data available for testing.


Now you can open up the SQL Management Studio and check everything is created successfully.


Finally execute the application and test.


There you have, few simple steps to connect your code first approach withSQL RDS.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s