Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Posts Tagged ‘sql’

Windows Azure – Connect to SQL Azure

Posted by Paul on November 13, 2011

We are now are ready with our SQL Azure database server and database. So we can proceed with connecting with the database. We can use our ADO.NET Connection class to connect to the database.

The steps involved here are:

  • Get the Database Server Name
  • Connect using SqlConnection class

The steps are following.

Get the Database Server Name

Sign in to the windows azure portal and click on the Database item from the left pane.

clip_image002

Then expand the subscriptions item and select the database server name. From the right hand side properties window, you can get the Fully qualified DNS Name of the server as shown in the figure below.

clip_image004

Copy your server name. Now open Visual Studio and create a new Azure project and add a web role into it.

Add a SqlDataSource component into it from the toolbox. In the properties window of the control, click on the ConnectionString property. From the drop down list select New Connection. You will be prompted with the following dialog.

clip_image006

Select Microsoft SQL Server from the list above and click continue. Now the Add Connection dialog will appear as shown below.

clip_image008

Enter the following

  • SQL Azure Server Name
  • User Name
  • Password

(Remember to check the Use SQL Server Authentication check box)

Now select the database we created and press Test Connection button. If you get the succeeded message box, you have a valid SQL Azure connection. Good Job!

clip_image010

Now press OK on the Add Connection dialog and from the properties window, you can collect the connection string as shown below.

clip_image012

Connect using SqlConnection class

Now we have the valid connection string, we can try connecting through code.

Open the code view of Default.aspx from the web role project. Add the following code into it. (Resolve the namespaces)

protected void Page_Load(object sender, EventArgs e)

{

string connectionString = “your connection string here”;

SqlConnection connection = new SqlConnection(connectionString);

connection.Open();

if (connection.State == System.Data.ConnectionState.Open)

Label1.Text = “Connection Succeeded!”;

else

Label1.Text = “Connection Failure!”;

}

Open the design view of Default.aspx and add a label control into it. You may remove the data source control from there.

Now execute the application and you can see the result as shown below.

clip_image014

If the message is Connection Succeeded you are having a valid connection established with SQL Azure.

Collecting Connection String from Windows Azure Portal

We can also get the connection string from the azure portal by selecting the database and clicking the View connection string button.

clip_image016

Then the following dialog box shows the connection string. The first one ADO.NET represents our needed connection string.

Summary

In this article we have seen how to get the database server name, get the connection string and connect it using c# code.

Advertisements

Posted in Azure | Tagged: , , , , , | Leave a Comment »

Windows Azure – Create new SQL Azure Server and Database

Posted by Paul on November 13, 2011

Now we can proceed with creating the database in the azure account. The steps involved in this are following.

  • Create new subscription
  • Create new server
  • Create new database

New subscription is already created and we can reuse it. So we can proceed with the next 2 steps.

Create new server

Sign in to the windows azure portal and click the Database category from the left pane as shown below.

clip_image002

Wait for a few seconds and you will be getting the main pane ready as below:

clip_image004

Click on the Create a new SQL Azure Server item from the above screen. The following screen appears.

clip_image006

In the above dialog select the Subscription and click next to continue.

clip_image008

In the above screen select the Region and click Next to get the next screen.

clip_image010

In the above screen enter the administrative login and password. (The usual names like sa, admin etc. are reserved and entering is not allowed)

Note: On entering a valid login name and passwords only, the Next button will get enabled.

On clicking next, we get the following screen.

clip_image012

Use the Add button to add the IP address range. We need to enter the range for getting client access to the server. For demonstration I have entered 0.0.0.0 to 255. 255. 255. 255 to open all IP get access to it.

Now click the Finish button.

You can open the subscription item from the left top pane to see the new server and default databases inside it. You will be provided with a master database with read only access to it.

clip_image014

Create a new Database

Now we can proceed with creating our database. To achieve this click on the Create button from the top ribbon as shown below.

clip_image016

The following dialog box appears:

clip_image018

Enter the database name you prefer and select the default options for other entries, click Ok button.

You are now ready with the new database.

clip_image020

Now we are ready with the new database. In the upcoming articles we can see how to use the database using ADO.NET classes.

Summary

In this article we have seen how to create a database server and database in SQL Azure. You can find more information on SQL Azure here.

Posted in C# | Tagged: , , , , | Leave a Comment »

Windows Azure – Create new SQL Azure Server and Database

Posted by Paul on November 13, 2011

Now we can proceed with creating the database in the azure account. The steps involved in this are following.

  • Create new subscription
  • Create new server
  • Create new database

New subscription is already created and we can reuse it. So we can proceed with the next 2 steps.

Create new server

Sign in to the windows azure portal and click the Database category from the left pane as shown below.

clip_image002

Wait for a few seconds and you will be getting the main pane ready as below:

clip_image004

Click on the Create a new SQL Azure Server item from the above screen. The following screen appears.

clip_image006

In the above dialog select the Subscription and click next to continue.

clip_image008

In the above screen select the Region and click Next to get the next screen.

clip_image010

In the above screen enter the administrative login and password. (The usual names like sa, admin etc. are reserved and entering is not allowed)

Note: On entering a valid login name and passwords only, the Next button will get enabled.

On clicking next, we get the following screen.

clip_image012

Use the Add button to add the IP address range. We need to enter the range for getting client access to the server. For demonstration I have entered 0.0.0.0 to 255. 255. 255. 255 to open all IP get access to it.

Now click the Finish button.

You can open the subscription item from the left top pane to see the new server and default databases inside it. You will be provided with a master database with read only access to it.

clip_image014

Create a new Database

Now we can proceed with creating our database. To achieve this click on the Create button from the top ribbon as shown below.

clip_image016

The following dialog box appears:

clip_image018

Enter the database name you prefer and select the default options for other entries, click Ok button.

You are now ready with the new database.

clip_image020

Now we are ready with the new database. In the upcoming articles we can see how to use the database using ADO.NET classes.

Summary

In this article we have seen how to create a database server and database in SQL Azure. You can find more information on SQL Azure here.

Posted in C# | Tagged: , , , , | Leave a Comment »

Windows Azure – SQL Azure Introduction

Posted by Paul on November 13, 2011

Remembering from the storage type article, the 3 types of storage were:

  • Local Storage
  • Windows Azure Storage
  • SQL Azure Storage

In this article we are emphasizing on SQL Azure Storage. The important features are listed and we will be creating an database in the online storage account.

The features are mentioned below:

  • SQL Server equivalent in Cloud
  • Built on SQL Server Technologies
  • No installation needed
  • Transact SQL Support
  • ADO.NET and ODBC drivers supported
  • Available anywhere
  • Existing .Net Database skills are reusable here
  • Easier Scalability
  • Highly Fault Tolerant
  • Pricing involved

clip_image002

Note: The Sql Azure can be accessible from Azure applications as well as other applications like ASP.NET, Console Applications. Also the complete SQL Features are not available in SQL Azure. You can find more info here.

Features Explained

We can relate everything in our windows/asp.net world to azure world. The Sql Azure is the Sql Server equivalent in the cloud. There will be a server, database and connectivity using ADO.NET which we are familiar with. (Creation of server and database are discussed in the upcoming article.)

Connecting using ADO.NET

We can use the existing ADO.NET SQL Server classes to connect and manipulate the SQL Azure database.

Operation

Class

Connection

SqlConnection

Command

SqlCommand

Read

SqlDataReaders

Advantages

The SQL Azure database will be replicated on multiple servers and is more fault tolerant than the SQL Server database.

The automatic switching of server in case of server fault makes the SQL Azure have increased availability.

SQL Azure helps the database management easier by freeing up from:

  • Server Operating System Setup Overheads
  • SQL Server Setup Overheads
  • Scalability Setup Overheads

In the pre SQL Azure world, we need to setup the database server with the appropriate operating system, install the sql server, configure the server etc. But in SQL Azure we are free from all these overheads. This makes concentrating in the core aspects of the application.

In the SQL Azure, scalability is an easier task otherwise in Sql Server we have to deal with replication server configuration, principal and mirror server configuration etc. We can scale up and down based on the requirements of the application.

More information can be found here
Types of Database

In the SQL Azure there are two types of databases:

  • Web Edition
  • Business Edition

The Web Edition is the basic edition and right choice for a typical web application. This Database provides up to 5 GB of T-SQL based relational database. This edition is best suited for Web application, and Departmental custom apps.

The Business Edition SQL Azure DB provides up to 50 GB of T-SQL based relational database. This edition is best suited for Software as a Service applications, custom applications etc.

clip_image004

The billing also varies based on the edition. In our examples we will be using the Web Edition only.

Posted in C# | Tagged: , , , , , | Leave a Comment »

Windows Azure Platform Management Tool (MMC)

Posted by Paul on November 13, 2011

In this article, I would like to introduce a tool useful while developing Windows Azure applications.

The Platform Management Tool is a desktop application and it allows the developers to manage:

  • Hosted Services
  • Perform Diagnostics
  • Certificates
  • Storage Services
  • Blob, Table, Queue
  • Command Based Operations

Download

The latest tool can be downloaded from codeplex.com

Source Code

The source code of the tool is available here.

Using the MMC

Download the tool and execute the setup.

clip_image002

The files will be extracted to the specified folder. Now execute the StartHere.cmd file from location C:\WindowsAzure\MMC. The following wizard will appear.

clip_image004

Click Next to continue and it will do a scan of the system.

clip_image006

If all the required software found the status will be green. Click Next to continue and the installation will be started. A command window will be prompted like below:

clip_image008

Now press any key to continue and within few seconds the installation will be completed. The following screen will be visible.

clip_image010

The MMC tool will be automatically started as below. (You can also launch it from the desktop icon)

clip_image012

Expand the Windows Azure Management item and click on the Service Management item.

clip_image014

Enter your Subscription ID in the appearing dialog. (Subscription ID can be retrieved from the Windows Azure Portal)

Then Click on the API Certificate button. Your certificate will be automatically populated in the appearing dialog as shown below: (If no certificates are listed, then you need to create and add certificate into your azure account. This is explained the previous article)

clip_image016

Select the certificate and click Ok.

Now click Connect from the right pane as shown below:

clip_image018

Wait for a while and you will be connected to the service. Now you can explore the hosted services, storage services by clicking the respective item from the left pane.

The figure below shows the content of Blob Containers.

clip_image020

Summary

In this article the MMC tool was introduced. It should be noted that the Storage functionalities of the tool can be achieved with the Server Explorer of Visual Studio.

Posted in C# | Tagged: , , , , | Leave a Comment »