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.
- How to create a SQL Data base.
- How to allow IP Address to connect to your Azure Data base.
- How to use Data base script to create a new database for Gostyle bar.
- How to connect application with database
- Create a Windows Azure SQL Database using Windows Azure Management Portal
- Login to Windows Azure Management Portaland navigate to SQL Databases section and click “New”button on bottom-left.
- Select “SQL Database” then “Custom Create”
- 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
- 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.
How to allow IP Address to connect to your Azure Data base.
Please follow below document to configure IP address
How to run the script
Steps to run the SQL script are:
- Open SQL Server Management Studio
- Open Query Window
- Run Your data base script which you might have created
4.Script will create a new data base.Please see following example
How to connect application with newly created database
- 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 picture
- Delete the yourproject.edmx entity file
- Create new entity model : follow below steps to create new entity model
- Select Generate from Database option
Click on New Connection button
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
- 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.