Select Page

Azure Database Code Entity Framework

First time Azure and Entity framework user struggle to find exact steps.We thought of sharing steps how to exactly recreate  a data base in SQL Azure and integrate with .NET Code using entity framework.

Using this document covers.

  1. How to create a SQL Data base.
  2. How to allow IP Address to connect to your Azure Data base.
  3. https://azure.microsoft.com/en-in/documentation/articles/sql-database-configure-firewall-settings/
  4. How to use Data base script to create a new database for Gostyle bar.
  5. How to connect application with database
  1. Create a Windows Azure SQL Database using Windows Azure Management Portal
  2. Login to Windows Azure Management Portaland navigate to SQL Databases section and click “New”button on bottom-left.
  3. 1
  4. Select “SQL Database” then “Custom Create”
  5. 1.5
    1. You’ll see a modal pop-up for database settings

    NAME : Name of the database

    EDITION : WEB | BUSINESS ; WEB Edition supports up to 5 GB maximum and BUSINESS Edition supports up to 150 GB maximum size T-SQL based relational database. If you don’t need more than 5 GB choose WEB.

    COLLATION : Default database rules for sorting and comparing. Note that collation cannot be changed after creation

    SUBSCRIPTION : Select your subscription for billing purposes. You can move your databases between your subscriptions

    SERVER : Choose and existing SQL Server or create new SQL Database Server. Note that these are logical servers, not dedicated physical servers

    2

  1. If you chose to create a new SQL Database Server, you’ll have another modal pop-up.

LOGIN NAME/PASSWORD : create default login for your SQL Database Server

REGION : Windows Azure Datacenter

ALLOW WINDOWS AZURE SERVICES TO ACCESS THE SERVER : If you select this your applications and services             running in Windows Azure Datacenters may access to this server, equivalent to 0.0.0.0 to 0.0.0.0 firewall exception

rule. If you don’t select it only allowed IP addresses may reach to your SQL Database Server.

 

4

 

 

          How to allow IP Address to connect to your Azure Data base.

          Please follow below document to configure IP address

         https://azure.microsoft.com/en-in/documentation/articles/sql-database-configure-firewall-settings/

How to run the script

Steps to run the SQL script are:

  1. Open SQL Server Management Studio
  2. Open Query Window
  3. Run Your data base script which you might have created

5

4.Script will create a new data base.Please see following example

6

How to connect application with newly created database

  1. Generate Entity Framework from created Database
  • Go to Solution Explorer
  • Go to Yourproject.Data ( Your project is name of project which you are working and want to change the data connection
  • Go to Model folder
  • Update YourprojectModel.edmx file as shown in below picture7
  • Delete the yourproject.edmx entity file
  • Create new entity model : follow below steps to create new entity model
  • Select Generate from Database option8

Click on New Connection button

9

10

In the above dialog box specify (credential are just example)

  • ServerName –
  • Username –
  • Password –
  • Select database

Click on OK

Select all tables from DB to create entity model

Click on finish as shown below

1112

  • Model file will be generated like above
  • Now open the App.config file in Yourproject.Data folder
  • copy the new configuration generated as “YourProjectEntities” to Stylebar.service > yourproject.config file.
  • Rebuild the whole solution and hit F5 to run the project and login using

If you are able to login to your application you have successfully created and connected database.