Wednesday, September 23, 2009

My first SQL azure Application on the Cloud !!!

Hi Folks,

Few months ago, i worked with Azure Services, and since i'm interested to develop applications over the cloud which extensively use SQL Server as a backend, i used BLOBS to store my data... actually it wasn't that easy to use, but the product was still in beta in that time.

Recently, I have some time to develop and start using SQL Azure services, A big start by allowing us to create the Database over the website, then all other operations ( CRUD ) for the Database design and object model can be done using ADO.Net classes.

C# Code for connecting and creating a table over the cloud:

SqlConnectionStringBuilder connString2Builder;
connString2Builder = new SqlConnectionStringBuilder();
connString2Builder.DataSource = ""; // check your profile to know server name.
connString2Builder.InitialCatalog = "YourDB"; // you can create your own their.
connString2Builder.Encrypt = true;
connString2Builder.TrustServerCertificate = true;
connString2Builder.UserID = "myUserName";
connString2Builder.Password = "myPassword";

// Connect to the sample database and perform various operations
using (SqlConnection conn = new SqlConnection(connString2Builder.ToString()))
using (SqlCommand command = conn.CreateCommand())

// Create a table
command.CommandText = "CREATE TABLE MostafaTable(Col1 int primary key, Col2 varchar(20))";

// Insert sample records
command.CommandText = "INSERT INTO MostafaTable(col1, col2) values (1, 'string 1'), (2, 'string 2'), (3, 'string 3')";
int rowsAdded = command.ExecuteNonQuery();

// Query the table and print the results
command.CommandText = "SELECT * FROM MostafaTable";

using (SqlDataReader reader = command.ExecuteReader())
// Loop over the results
while (reader.Read())
Console.WriteLine("Col1: {0}, Col2: {1}",

-- To read more about SQL Azure services:

-- SQL Azure Forums:

Hope it helps.

Mostafa arafa

1 comment:

Anonymous said...

It is very interesting for me to read that article. Thanx for it. I like such themes and everything that is connected to this matter. I would like to read a bit more soon.