18 May 2012 @ 3:25 PM 

One of the most common questions in developing ASP.NET applications on Windows Azure is how to manage session state. The intention of this article is to discuss several options to manage session state for ASP.NET applications in Windows Azure.

What is session state?

Session state is usually used to store and retrieve values for a user across ASP.NET pages in a web application. There are four available modes to store session values in ASP.NET:

  1. In-Proc, which stores session state in the individual web server’s memory. This is the default option if a particular mode is not explicitly specified.
  2. State Server, which stores session state in another process, called ASP.NET state service.
  3. SQL Server, which stores session state in a SQL Server database
  4. Custom, which lets you choose a custom storage provider.

You can get more information about ASP.NET session state here.

In-Proc session mode does not work in Windows Azure

The In-Proc option, which uses an individual web server’s memory, does not work well in Windows Azure. This may be applicable for those of you who host your application in a multi-instance web-farm environment; Windows Azure load balancer uses round-robin allocation across multi-instances.

For example: you have three instances (A, B, and C) of a Web Role. The first time a page is requested, the load balancer will allocate instance A to handle your request. However, there’s no guarantee that instance A will always handle subsequent requests. Similarly,the value that you set in instance A’s memory can’t be accessed by other instances.

The following picture illustrates how session state works in multi-instances behind the load balancer.

Figure 1 – WAPTK BuildingASP.NETApps.pptx Slide 10

The other options

1.     Table Storage

Table Storage Provider is a subset of the Windows Azure ASP.NET Providers written by the Windows Azure team. The Table Storage Session Provider is,in fact, a custom provider that is compiled into a class library (.dll file), enabling developers to store session state inside Windows Azure Table Storage.

The way it actually works is to store each session as a record in Table Storage. Each record will have an expired column that describe the expired time of each session if there’s no interaction from the user.

The advantage of Table Storage Session Provider is its relatively low cost: $0.14 per GB per month for storage capacity and $0.01 per 10,000 storage transactions. Nonetheless, according to my own experience, one of the notable disadvantages of Table Storage Session Provider is that it may not perform as fast as the other options discussed below.

The following code snippet should be applied in web.config when using Table Storage Session Provider.

<sessionState mode="Custom" customProvider="TableStorageSessionStateProvider">   <providers>     <clear/>    <add name="TableStorageSessionStateProvider"         type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageSessionStateProvider" />   </providers>
</sessionState>

You can get more detail on using Table Storage Session Provider step-by-step here.

2.     SQL Azure

As SQL Azure is essentially a subset of SQL Server, SQL Azure can also be used as storage for session state. With just a few modifications, SQL Azure Session Provider can be derived from SQL Server Session Provider.

You will need to apply the following code snippet in web.config when using SQL Azure Session Provider:

<sessionState mode="SQLServer"
sqlConnectionString="Server=tcp:[serverName].database.windows.net;Database=myDataBase;User ID=[LoginForDb]@[serverName];Password=[password];Trusted_Connection=False;Encrypt=True;"
cookieless="false" timeout="20" allowCustomSqlDatabase="true"
/>

For the detail on how to use SQL Azure Session Provider, you can either:

The advantage of using SQL Azure as session provider is that it’s cost effective, especially when you have an existing SQL Azure database. Although it performs better than Table Storage Session Provider in most cases, it requires you to clean the expired session manually by calling the DeleteExpiredSessions stored procedure. Another drawback of using SQL Azure as session provider is that Microsoft does not provide any official support for this.

3.     Windows Azure Caching

Windows Azure Caching is probably the most preferable option available today. It provides a high-performance, in-memory, distributed caching service. The Windows Azure session state provider is an out-of-process storage mechanism for ASP.NET applications. As we all know, accessing RAM is very much faster than accessing disk, so Windows Azure Caching obviously provides the highest performance access of all the available options.

Windows Azure Caching also comes with a .NET API that enables developers to easily interact with the Caching Service. You should apply the following code snippet in web.config when using Cache Session Provider:

<sessionState mode="Custom" customProvider="AzureCacheSessionStoreProvider">   <providers>     <add name="AzureCacheSessionStoreProvider"           type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"           cacheName="default" useBlobMode="true" dataCacheClientName="default" />   </providers>
</sessionState>

A step-by-step tutorial for using Caching Service as session provider can be found here.

Other than providing high performance access, another advantage about Windows Azure Caching is that it’s officially supported by Microsoft. Despite its advantages, the charge of Windows Azure Caching is relatively high, starting from $45 per month for 128 MB, all the way up to $325 per month for 4 GB.

Conclusion

I haven’t discussed all the available options for managing session state in Windows Azure, but the three I have discussed are the most popular options out there, and the ones that most people are considering using.

Windows Azure Caching remains the recommended option, despite its cons but developers and architects shouldn’t be afraid to decide on a different option, if it’s more suitable for them in a given scenario.

This post was also published at A Cloud Place blog.

Posted By: admin
Last Edit: 18 May 2012 @ 03:25 PM

EmailPermalinkComments (1)
Tags
 13 Aug 2011 @ 1:52 PM 

Introduction

The Windows Azure Platform is a Microsoft cloud platform used to build, host and scale web applications through Microsoft datacenters. Customers are given privilege to scale VM instance up and down in the matter of a few minutes. Although this flexibility would indeed very useful, it may affect the way we architect and design the solution.
One of the essential aspect that we would need to take into account is session state. Traditionally, if you are running one single server, going for default InProc session state will just work fine. However, when you have more than one server hosting your application, this may be a challenge for us. Similarly this scenario applies to Cloud environment.
This article describes various options to handle Session State in Windows Azure. For each option, I’ll start with common introduction as brief information, follow by various advantages and disadvantages, and finalize by recommendation and suggestion.
As prerequisite, I would assume the readers are familiar with the basic, what Session is and how it works…

Various Options to Manage Session State in Windows Azure

1. InProc Session

image_73B6713B
InProc session state maybe is the best performed option (in term of access time) and the default when you are not specifying one. It actually stores the session in web server’s memory. Therefore, the access is very fast since hitting to memory is extremely speedy.
I had a post last November 2011 that described In-proc Session does not work well in Windows Azure. Well, in fact, it may be fine if you just run on single instance. However, I won’t recommend you to just spin up single instance at production environment, unless you tolerate some downtime. To meet the 99.95% SLA, we are required to spin at least 2 instance per role.

Advantages

  • Very fast access since the session information is stored in memory (RAM)
  • No extra cost as it will be using your VM’s memory

Disadvantages

  • As mentioned above, this will only valid for single instance. If you use more than one instance, the inconsistency will happen.
*The rest of the option will tackle the single instance issue as they use centralized medium.

2. Table Storage Session Provider

image20_73A64B6E
Table Storage Provider is actually a subset of Windows Azure ASP.NET Providers written by some Microsoft folks. The Session Provider is actually a custom provider that is compiled into a dll, centralize the session information in Windows Azure Table Storage. You may download the package from here. Clicking on the “Browse Code” section will show you pretty comprehensive example of how to implement this on your project.
The way how it actually works is to store each session in Table Storage as could be seen in below screenshot. Each record will have its expired column that describe the expired time of each session if there’s no interaction from the user.

Advantages

  • Cost effective. In essence, Windows Azure Storage only charge you $ 0.15 per GB per month.

Disadvantages

  • Not officially supported by Microsoft
  • Performance may not be very good. I experience a pretty bad experience on performance when using Windows Azure Storage provider.
  • Need to clear unused session.
For each time a session (with properties including expiry time) is created on a session table. For the subsequent request, it will be check against the table to see if it exists. For the scenario we need delete the record which expiry time equals or older than current time. This is to enable timeout when there is no activity against session.
In order to automatically delete expired session, most of the time we use Windows Azure Worker Role to perform the batch activity.

SQL Azure Session Provider

image_2A13AB19
SQL Azure Session Provider is actually a modified version of SQL Server Session Provider provided some changes that had been made on TSQL function, in order to comply SQL Azure. It is identified some issue on the original script and some folk posted the resolution or you can download it
.

Advantages

  • Cost effective. Although it may not be cost effective compare to table storage, it’s still pretty affordable, especially when combining it into the main database.

Disadvantages

  • Not official support by Microsoft
  • Need to clear unused session
For each time a session (with properties including expiry time) is created on a session table. For the subsequent request, it will be check against the table to see if it exists. For the scenario we need delete the record which expiry time equals or older than current time. This is to enable timeout when there is no activity against session.
In order to automatically delete expired session, most of the time we use Windows Azure Worker Role to perform the batch activity.

Windows Azure AppFabric Caching

image_797CDB08
Windows Azure AppFabric Caching is actually the recommended option and officially supported by Microsoft. AppFabric Caching is distributed in-memory cache service. It is automated provisioned based on Windows Server AppFabric Caching Technology.

Advantages

  • In memory cache, very fast access
  • Officially supported by Microsoft

Disadvantages

  • The cost is relatively high. The pricing starts from $ 45 per month for 128 MB and all the way up to $ 325 per month for 4 GB.

Conclusion

To conclude this discussion, there’re actually multiple ways of managing session in Windows Azure. All of them have pros and cons. It’s actually up to us to decide which one to use that fits better circumstance.

Posted By: admin
Last Edit: 17 Oct 2012 @ 03:15 AM

EmailPermalinkComments (0)
Tags
 10 Jul 2011 @ 9:08 AM 

In the last post, I showed you how to set timezone in Windows Azure. In this post, I would like to show how to manage timezone in SQL Azure.

Current Limitation

At the time this post is written, unfortunately there’s no to change SQL Azure timezone.

image_286799A2

http://social.technet.microsoft.com/wiki/contents/articles/sql-azure-faq.aspx

Selecting Default UTC Timezone VS Local Timezone

Likewise in Windows Azure VM, SQL Azure use UTC as default timezone, regardless which datacenter you choose. Meaning that when you call getdate() function, it’s going to return you the current date and time according to the server’s timezone.

1. Use Default UTC TImezone

If you are building a new system with new created database without any existing data, I would consider UTC default timezone is fine.You can store the time as UTC inside your database. Optionally, if you want to ensure your local timezone to be displayed in UI, you can actually control it at the presentation layer.

2. Use Local Timezone

However, imagine you have existing application with bunch of data (including date time column) using your own local timezone, it will definitely messed up when you move to SQL Azure UTC timezone. The data inconsistency will definitely occur. Then you’ll need to determine either:

a. to convert your current data to UTC-timezone compliance OR

b. change your any SQL Objects (including functions, stored procedure, etc.) to match your local date time.

It’s a Tricks / Workaround, Not Actually a Solution

I’ve tried to look for various solution on the internet, mailing list, or even talk with Microsoft MVPs and Product Group folks but still there’s no single answer that could really satisfy me. Accordingly, I would call the following technique as a trick or workaround, instead of saying a solution.

Back to the second point discussed at above, converting your current data to UTC-timezone maybe very painful especially you have a lot of date and time data inside your table. In my personal opinion, I would prefer changing SQL Objects. But one very important consideration is to make it flexible and elegant enough, especially when in the future, we would need to convert back to the original state.

Well, you could definitely Find and Replace any objects inside SQL schema from getdate() to select dateadd(hh,8,getdate()). But of course it’s not going to be a nice way. As such, here’s what I’ve done to make it better. Winking smile

1. Create a User-Defined Function: GetLocalDate()

CREATE FUNCTION [dbo].[GetLocalDate]


(


    @TimezoneDiffInHour TINYINT = 8


    -- default set to 8 (GMT +8 = Singapore Timezone) 


)


RETURNS DATETIME


AS


BEGIN


    RETURN DATEADD(Hh, @TimezoneDiffInHour , GETUTCDATE())


END

 

To call this function, you can either use:

SELECT dbo.GetLocalDate(DEFAULT)


-- OR


SELECT dbo.GetLocalDate(8)


-- 8 denotes Singapore Timezone

2. Script Out The Entire Database Schema

You would need to find and replace entire SQL objects to identify which of the object that use getdate() function. Before doing so, you’ll of course need to generate the entire database schema. You can do so using the generate script wizard in SQL Server Management Studio.

image_554C1509

3. Find and Replace getdate() with dbo.GetLocalDate(DEFAULT)

The next step is to find which the database object that use getdate() function. Change it to dbo.GetLocalDate(DEFAULT). Execute it by altering the existing object.

By doing so, I can easily switch to UTC timezone system, just by only alter my GetLocaDate() function with Default value 0 on @TImezoneDiffInHour parameter. I don’t have to regenerate and convert back my objects again.

 

Frankly speaking, it may not the the best solution, but it just serves as workaround and fits my need. I won’t be surprise if there’s a better solution in the future, hopefully we can natively change the timezone in SQL Azure.

Posted By: admin
Last Edit: 17 Oct 2012 @ 03:18 AM

EmailPermalinkComments (1)
Tags
Tags:
Categories: SQL Azure
 14 May 2011 @ 2:44 PM 

In certain circumstances it’s very challenging for us to troubleshoot SQL Azure issues since the SQL Azure Server is actually a virtual server (TDS Endpoint), not an actual physical machine as current on-premise SQL Server is.

As announced by SQL Azure team, SQL Azure Diagnostic Tool is a tool that has been developed to shorten the data collection process when troubleshooting SQL Azure issues. This tool is available to be download for free from here.

Requirement

SQL Azure Diagnostic Tools is built on top of .NET 4.0 and SQL Server Reporting, as such some prerequisites are needed:

Having done installing the SQL Azure Diagnostic Tool, you will see a light-weight tool as this:

image_thumb_748A2A82

To use it, simply enter details of your SQL Azure account including:

  • server name
  • database name
  • username
  • password

And simply click on GO button to begin the diagnostic.

SQL Azure Diagnostic Tool will provide you a execution time of various kind of queries so that you could analyze it in more detail, what is the root cause your application’s issue.

It captures:

  • Top 10 CPU consumption
  • Top 10 Duration
  • Top 10 Logical I/O
  • Top 10 Physical I/O

image_thumb_0F26A0CF

I believe this is still an very early stage of tool and will be keep improving and improving. We would hope that in the next version of update, we can see more comprehensive analysis.

Posted By: admin
Last Edit: 17 Oct 2012 @ 03:30 AM

EmailPermalinkComments (0)
Tags
Tags:
Categories: SQL Azure
 11 Oct 2010 @ 2:00 PM 

If you want to see how much size has you used in your SQL Azure database, you can definitely see it on the SQL Azure Developer Portal as shown below.

image_6058D5EB

However, for some reason, sometimes you would either need to get the size more precisely or retrieve the numbers programmatically.

Calculating Database Size

Here’s the query for you to retrieve the size of your database.

select 
      sum(reserved_page_count) * 8.0 / 1024 as ''Database Size''
from 
      sys.dm_db_partition_stats 

After running in on my SQL Server Management Studio R2, here’s the result:

image_6566226C

Calculating Each Table in the Database

If you need to explore in more detail how much size for each table, you can also use the following query to see.

select 
      sys.objects.name as ''TableName'', sum(reserved_page_count) * 8.0 / 1024 as ''Size (in MB)''
from 
      sys.dm_db_partition_stats, sys.objects 
where 
      sys.dm_db_partition_stats.object_id = sys.objects.object_id
group by sys.objects.name

 
Running those script on the management studio will result:
image_1D2840C3

References

You may want to learn more about SQL Azure tips and tricks, be sure to check out the following posts:

Hope this helps.

Posted By: admin
Last Edit: 17 Oct 2012 @ 07:03 AM

EmailPermalinkComments (0)
Tags
Categories: SQL Azure
 08 Sep 2010 @ 2:04 PM 
This is an additional post for Migrating ASP.NET Application to Windows Azure series. Please refer to previous related posts if you have not read it before.

Introduction

In the step 6 of the Part 3 post, remembering that I commented some portion of the code in AdminPhoto.aspx and App_CodePhotoManager.cs which unable be run directly on Windows Azure. What actually the feature does is enable us to perform bulk copy from the web server’s folder namely “upload” to the database. However, those code could not simply work on Azure since we have no control over the “upload” folder when our app has been uploaded to Windows Azure.
image_0D77A98A

The idea to implement similar feature

As I promise to answer to this issue, in this post I’ll show you step-by-step how to implement similar feature. We will be do those things in 2 files: AdminPhoto.aspx and AdminPhoto.aspx.cs.
The idea to use blob storage as replacement of “upload” folder. We can upload our photos to blob storage by using tool such as Azure Storage Explorer.
image_78315616
Assuming that I’ve created a container called “photos” and uploaded some photos in that container.
When user is ready to upload the photos inside the container, they will click on Import and what our application do is to store these photos to SQL Azure using the existing class library “PhotoManager.cs”.
*Please note that actually the better practice is to store those file in blob storage rather than SQL Azure since scalability and cost-efficient concern. However, since I’ve used SQL Azure to store the data (including photos) from the beginning of this post, I’ll just continue to do with respect to consistency manner.

Step by Step: how to implement

1. DataConnectionString setting on compute role.

Since we are using Azure Storage, we’ll need to add a setting on intended role (in my sample: PersonalWebRole) as shown below.
image_4D40A439
To do that, double click on PersonalWebRole which is located below CloudServicePersonalRoles folder. Subsequently click on Settings tab.
You may note that in the example I use DevelopmentStorage, of course you could be able to use the “real” Azure Storage. All you need to do is to create a Azure Storage Service and then specify the service name as well as the key as the value.

2. Some codes in WebRole.cs

To tell WebRole that “please refer to the setting to retrieve the storage value”, we’ll need to add something on OnStart method inside WebRole.cs. (the yellow highlighted section).
   1: public override bool OnStart()

 

   2: {

 

   3:     DiagnosticMonitor.Start("DiagnosticsConnectionString");

 

   4:

 

   5:     RoleEnvironment.Changing += RoleEnvironmentChanging;

 

   6:

 

   7:     CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>

 

   8:         {

 

   9:             configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

 

  10:         });

 

  11:

 

  12:     return base.OnStart();

 

  13: }

3.  In AdminPhoto.aspx file.

I replace the commented section with the following codes.
   1: <div id="sidebar">

 

   2: <asp:ScriptManager ID="ScriptManager1" runat="server">

 

   3: </asp:ScriptManager>            <h4>Bulk Upload    Photos</h4>

 

   4:     <p>The following files were found in your <b><%
   1:  = ddlBlobContainer.SelectedValue
%></b> folder, in your Azure Blobs Storage.
   5:     <br />Click on <b>Import</b> to import these pictures to your photo album.</p>

 

   6:     <asp:UpdatePanel ID="up" runat="server">

 

   7:         <ContentTemplate>

 

   8:             Select Container: <asp:DropDownList AutoPostBack="true" ID="ddlBlobContainer" runat="server"

 

   9:             onselectedindexchanged="ddlBlobContainer_SelectedIndexChanged" />

 

  10:             <br /><br />

 

  11:             <div style="height:300px; overflow:scroll; text-align:center; border:solid 1px #fff" >

 

  12:                 <asp:ListView runat="server" id="UploadList" repeatcolumns="1"

 

  13:                     repeatlayout="table" repeatdirection="horizontal"

 

  14:                     onitemdatabound="UploadList_ItemDataBound" >

 

  15:                     <LayoutTemplate>

 

  16:                         <div style="border:solid 1px #000; padding:5px; margin:5px" runat="server" id="itemPlaceholder">

 

  17:                         </div>

 

  18:                     </LayoutTemplate>

 

  19:                     <ItemTemplate>

 

  20:                         <asp:Image ID="img" runat="server" Width="120px" />

 

  21:                     </itemtemplate>

 

  22:                     <ItemSeparatorTemplate><br /><br /></ItemSeparatorTemplate>

 

  23:                     <EmptyDataTemplate>the container doesn''t contain any photos</EmptyDataTemplate>

 

  24:                 </asp:ListView>

 

  25:             </div>

 

  26:         </ContentTemplate>

 

  27:     </asp:UpdatePanel>

 

  28:     <asp:ImageButton ID="ImageButton1" Runat="server" onclick="Button1_Click" SkinID="import" />

 

  29: </div>

Let me explain you how these things were added
a. I added a DropDownList called ddlBlobContainer. This ddlBlobContainer will be used to list out all of our blob containers that were associated with our storage account.
b. When we select on one of the ddlBlobContainer, we’ll fetch all blob item in that container and display it to user interface (UI).  l use ListView as UI container rather than of using DataList. Inside the ListView, I added Image object to show the thumbnail display, so that use could be able to see it before performing bulk copy.
c. I use UpdatePanel to enable ajax functionality so that the browser won’t be refreshed in full page view. (Remember that we’ll also need to include the ScriptManager in order to use UpdatePanel).

4. In AdminPhoto.aspx.cs file.

a. The next thing to do when using Azure Storage is to initialize the storage account as well as object that we are going to use.
   1: private static bool storageInitialized = false;

 

   2: private static object gate = new Object();

 

   3: private static CloudBlobClient blobStorage;

 

   4:

 

   5: private void InitializeStorage()

 

   6: {

 

   7:     if (storageInitialized) return;

 

   8:     lock (gate)

 

   9:     {

 

  10:         if (storageInitialized) return;

 

  11:         try

 

  12:         {

 

  13:             var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

 

  14:             blobStorage = storageAccount.CreateCloudBlobClient();

 

  15:             CloudBlobContainer container = blobStorage.GetContainerReference("photos");

 

  16:             container.CreateIfNotExist();

 

  17:

 

  18:             var permission = container.GetPermissions();

 

  19:             permission.PublicAccess = BlobContainerPublicAccessType.Container;

 

  20:             container.SetPermissions(permission);

 

  21:         }

 

  22:         catch (Exception ex)

 

  23:         {

 

  24:             throw new Exception("Error : " + ex.Message);

 

  25:         }

 

  26:         storageInitialized = true;

 

  27:     }

 

  28: }

  • The storageInitialized variable is used as flag to indicate whether the storage has been initialized
  • The gate variable is to be used along with “lock” statement, to ensure that other threads won’t enter the critical section before the resource has been released.
  • The blobStorage object serves as CloudBlobClient, to manipulate the blob of container.
  • In the InitializeStorage method, we get the connection value from the settings, create cloud blob client, get / create the specific container (In this example called “photos”) and finally set the permission of the container to public access.
b. Subsequently, I added BindUploadList() method which fetches blob from the container and display it to the listview.
   1: private void BindUploadList()

 

   2: {

 

   3:     CloudBlobContainer container = blobStorage.GetContainerReference(ddlBlobContainer.SelectedValue);

 

   4:     IEnumerable<IListBlobItem> blobItems = container.ListBlobs();

 

   5:

 

   6:     var photoBlobs = from i in blobItems

 

   7:                      where i.Uri.AbsoluteUri.ToLower().EndsWith(".jpg")

 

   8:                      || i.Uri.AbsoluteUri.ToLower().EndsWith(".png") ||

 

   9:                      i.Uri.AbsoluteUri.ToLower().EndsWith(".gif")

 

  10:                      select i;

 

  11:

 

  12:     UploadList.DataSource = photoBlobs;

 

  13:     UploadList.DataBind();

 

  14: }

I also ensure that only file that ends with .jpg, .png, gif will be displayed.
c. The next thing is to implement the UploadList_ItemDataBound method to handle the ItemDataBound event.
   1: protected void UploadList_ItemDataBound(object sender, ListViewItemEventArgs e)

 

   2: {

 

   3:     if (e.Item.ItemType == ListViewItemType.DataItem)

 

   4:     {

 

   5:         IListBlobItem blobItem =  ((ListViewDataItem)e.Item).DataItem as IListBlobItem;

 

   6:         Image img = e.Item.FindControl("img") as Image;

 

   7:         img.ImageUrl = blobItem.Uri.AbsoluteUri;

 

   8:     }

 

   9: }

d. To ensure that each time the photos would be refreshed when container was selected, I implemented the following snippet.
   1: protected void ddlBlobContainer_SelectedIndexChanged(object sender, EventArgs e)

 

   2: {

 

   3:     BindUploadList();

 

   4: }

e. In the Page_Load method, I get the setting first and then dump the blob containers to the dropdownlist, so that user could select the available container.
   1: protected void Page_Load(object sender, EventArgs e)

 

   2: {

 

   3:     if (!Page.IsPostBack)

 

   4:     {

 

   5:         InitializeStorage();

 

   6:

 

   7:         var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

 

   8:         blobStorage = storageAccount.CreateCloudBlobClient();

 

   9:

 

  10:         IEnumerable<CloudBlobContainer> cloudBlobContainers = blobStorage.ListContainers();

 

  11:         ddlBlobContainer.DataSource = cloudBlobContainers;

 

  12:         ddlBlobContainer.DataTextField = ddlBlobContainer.DataValueField = "Name";

 

  13:         ddlBlobContainer.DataBind();

 

  14:

 

  15:         BindUploadList();

 

  16:     }

 

  17: }

f. When the button “Import” was clicked, I loop through all the available photo in the container. For each blob item in the container, I’ll read the blob item, buffer it into array of byte, and finally submit the photos to the SQL Azure.
   1: protected void Button1_Click(object sender, ImageClickEventArgs e) {

 

   2:     CloudBlobContainer container = blobStorage.GetContainerReference("photos");

 

   3:

 

   4:     foreach (IListBlobItem blobItem in container.ListBlobs())

 

   5:     {

 

   6:         CloudBlob obj = container.GetBlobReference(blobItem.Uri.AbsoluteUri);

 

   7:         BlobStream blobStream = obj.OpenRead();

 

   8:

 

   9:         System.Drawing.Image objImage = null;

 

  10:         objImage = System.Drawing.Image.FromStream(blobStream);

 

  11:

 

  12:         string uniqueBlobName = Guid.NewGuid().ToString();

 

  13:         byte[] buffer = new byte[obj.OpenRead().Length];

 

  14:         obj.OpenRead().Read(buffer, 0, (int)obj.OpenRead().Length);

 

  15:

 

  16:         PhotoManager.AddPhoto(Convert.ToInt32(Request.QueryString["AlbumID"]), uniqueBlobName, buffer);

 

  17:     }

 

  18:     GridView1.DataBind();

 

  19: }

5. Verification

Let’s press Run button and see how it works!
a. We’ll need to login as administrator first before we can perform bulk upload.
image_516667FF
b. Having done so, please proceed to Manage link and click Edit on one of the Album.
image_000FBED8
c. You can now see the list of container in the dropdownlist, once you select one of them, the photos are refreshed accordingly.
image_75565152
Now, click on the Import button. In few moments, you can see that, you’ve successfully uploaded the photos.
image_70E3BA5B
Alright, we are now done.
I hope you enjoy this post and would be useful for you. See you at another post.
Posted By: admin
Last Edit: 17 Oct 2012 @ 09:19 AM

EmailPermalinkComments (0)
Tags
 27 Aug 2010 @ 2:15 PM 

It was a great opportunity to talk about SQL Azure to SQL User group Singapore. In a nutshell, SQL Azure is SQL database as service that is hosted on the Microsoft cloud platform.

In the talk, I started my presentation with overview idea of cloud computing, introducing Azure Service Platform, and finally deep dive on more detail on SQL Azure.

 image_02CF665Dimage4_49647A01

As usual, rather than showing presentation slide, I also showed the audience 4 demos including:

 image_078DE4AF
Connecting and administering SQL Azure
 image_6BD932EB
Migrating to SQL Azure
 image_62F904D2
Spatial support in SQL Azure
 image_4402455A
Introducing Houston
Silverlight version of SQL Azure management tools

There are a few photos taken as followings.

DSCN0881_3BFA7D2BDSCN0883_20094833DSCN0884_444E2CB5

Finally, you can download my presentation slide here.

Posted By: admin
Last Edit: 17 Oct 2012 @ 09:29 AM

EmailPermalinkComments (1)
Tags

 Last 50 Posts
 Back
Change Theme...
  • Users » 123
  • Posts/Pages » 73
  • Comments » 86
Change Theme...
  • VoidVoid
  • LifeLife
  • EarthEarth
  • WindWind « Default
  • WaterWater
  • FireFire
  • LightLight

About Me



    No Child Pages.