Understanding SQL Azure - Part Two

Introduction

This article will cover the following things,

  • Pre-requisites
  • Implementation – Create a simple Web application
  • Implementation – Connect the application with SQL Azure using EF.

Pre-requisites

Implementation – Create a simple Web application

Steps to be followed,

  • Open Azure portal and go to SQL databases section and click on the Add symbol to add “SQL database”

  • Then choose empty template with MVC option checked there

  • Create a Home Controller in the Controllers folder.

  • Create a View named as Index and write the sample code in. cshtml file for e.g. “web app created on 06-08-2017”.

Implementation – Connect the application with SQL Azure using EF.

Steps to be followed,

  • Right click on the project and install Entity Framework nugget package by choosing the option “Manage Packages”

  • Add .edmx file to use a DB first approach and connect with the SQL Azure entities.

  • Choose the DB first approach there

  • Extract the server-name from the SQL Azure DB’s properties on the portal and create a SQL server connection using the credentials and then choose the DB from the there and press OK

  • Then, choose the YES option to having the “sensitive data in connection string” and press on Next.

  • Choose the customer table from the menu and click on Finish.

  • Now go the controller and add some code to insert an entry into the Customer table

  • Run the application and check the Customer table data from the SQL Server Object Explorer

Please find the attached zip file for reference (restore packages and build the project before use),happy learning!


Similar Articles