Search Results For : ASP.NET

Connecting to SQL Azure with ASP.NET

Recently, I have been working with Windows Azure and SQL Azure for my new project and because of this, a good amount of developer friends came to me and wanted me to share more about it hence I decided to write it down as a blog post for anyone who is interested to know about it.

What is SQL Azure?
SQL Azure is Microsoft’s Relational Database offering on the Cloud. It is build from the foundation of SQL Server It helps to actually ease the provisioning and deployment of many databases. It is easily scalable per se.

This blog post is going to show you how easy is it for you to connect to SQL Azure, it actually works the same way as a normal SQL Server Connection, the main difference is the connection string. The username is your username setup at SQL Azure @ Server name. You can download the full sample project with CRUD ( Create, Retrieve, Update, Delete ) at the end of this post.

///
/// Connection to SQL Azure Database
///
public void ConnectToDatabase()
{

//Connection String
//data source=SERVER URL;
//initial catalog= Database name;
//User ID=User ID @ Server Name;
//Password=Password;
string connectionString = “data source=quxm9ku7nz.database.windows.net;initial catalog=fiveaboutme;User ID=guohong@quxm9ku7nz;Password=*****;”;
if (conn.State != ConnectionState.Open)
{
conn.ConnectionString = connectionString;
conn.Open();
comm.Connection = conn;
}
comm.Parameters.Clear();
}

You can download the project file from here.
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Code%20Guide/SQL%20Azure/SqlAzureConnection.zip

Please take note that you have to change the Server Name, Username, Password at the connection string to make this work. You should run the following script to the table first.
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Code%20Guide/SQL%20Azure/SQLAzureConnection.sql