Entity Framework With Microsoft Azure SQL

To use SQL Azure with your Entity Framework, first create an SQL database first in your Azure account. If you want learn more about SQL Azure then follow the following links:

So, let’s make an SQL database. Here are the steps,

Go to your Azure account find New, Data + Storage, then click SQL Databases.

storage

Fill the details and proceed to next.

details

After creating SQL Azure database successfully, then just go to Visual Studio and open Server Explorer. Just login with Azure Account and find the database created in Azure.

database

Right click on it and open it with SQL server Object Explorer so that we can create table and manage my database from wizard.

wizard

Just enter your database authentication details which were entered by you on the Azure portal to create a database and make sure that a client IP address has been added in to server configurations.

configuration

After connection with SQL Azure database into Server Explorer, you can see the database and all its tables and other things but I am not having any table yet, so make a table first. For that, right click on tables section and add a new table.

add

table

Just write your create table script on the script section and at last just click on update button.

update

Now, you’ll get dialog where you have to click on “Update Database” button.

Update Database

Now it’s creating a table you see your query updates in Data tools options.

tools

Just go to back on SQL Server object explorer and refresh tables. You’ll get the new table created by your query.

column

Now just add an ASP.NET or any other application where you want to use this database. I am going to use an ASP.NET project to use this database with entity framework.

framework

Now just add an Entity framework.

add

Select any one, but I am going to use Database first with entity.

Database

Now just make connection with Azure cloud service where your SQL Azure is hosted. For that you can go to your portal and get connection string.

connection

connection

Copy that and open it in text file and find server name.

server

Copy Server name and user id,

server

Use them and make a successful connection.

connection

connection

Give a name to your entity and select your tables which you want to use.

tables

Now this is your model file.

file

Now just add a ASP Web Form to write operations.

operations

Just use some textbox to get the test information from page and a button. On button click event write code to add an object to an entity table as in the following code.

code

Test code to save an object information to table.

object

Now at last just run this application and enter some details and click on button.

button

After that, you’ll get the message “Done !!” as I use to notify all done successfully.

message

Go to table and right click on table in SQL server object explorer and find View Data option.

option

So this is the data entered by you from ASP form.

form

I hope you enjoyed this article. Stay tuned with me for more articles on Azure and other Microsoft technologies.

Thanks.

Connect (“Nitin Pandit”);

Read more articles on Azure:


Similar Articles