Windows Azure – How to migrate data from SQL Server to a Storage account

Starting from this great article https://azure.microsoft.com/en-gb/documentation/articles/storage-dotnet-how-to-use-tables/ we started by including the required imports:

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Table;
using System.Configuration;
using System.Data.SqlClient;

Continue reading “Windows Azure – How to migrate data from SQL Server to a Storage account”

Windows Azure storage tables – How to delete a table in C#

Namespace declarations

Add the following code namespace declarations to the top of any C# file in which you wish to programmatically access Azure Storage.

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Table;

 try
            {
                // Retrieve the storage account from the connection string.
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                        ConfigurationManager.AppSettings["StorageConnectionString"]);

                // Create the table client.
                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

                // Create the table if it doesn't exist.
                //Table names must be unique within an account.
                //Table names may contain only alphanumeric characters.
                //Table names cannot begin with a numeric character.
                //Table names are case-insensitive.
                //Table names must be from 3 to 63 characters long.
                //Some table names are reserved, including "tables". Attempting to create a table with a reserved table name returns error code 404 (Bad Request)..
                string strTableName = txtClientDB.Text.Trim().Replace("_", "") + "erp";
                strTableName = strTableName.ToLower();
                CloudTable table = tableClient.GetTableReference(strTableName);
                // Delete the table it if exists.
                table.DeleteIfExists();
                lblSuccess.Text = "Delete succeeded";
                lblSuccess.Visible = true;
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text = ex.Message;
            }

https://azure.microsoft.com/en-gb/documentation/articles/storage-dotnet-how-to-use-tables/

Choosing Windows Web Hosting

Windows Azure and Server 2012+ Web hosting provides web hosting on Windows operating system platform.

Microsoft Corporation provides host based software operating system for servers. Windows Azure web hosting programs are considered to be easy to cope with, reliable and inexpensive.
The simplicity of the Windows Azure is what stands out with Cloud API and other applications. Windows provides its users with friendly, familiar environment that is easy to work with. Today as so much work has been done by developers it’s very easy to administrate your site with using Windows/ Server Side operating system. The Windows Azure platform is also reliable.  Continue reading “Choosing Windows Web Hosting”

How to upload all files from a folder on Microsoft Azure Storage

If you are working with Microsoft Cloud, you must have had the need to move a few files (in bulk) from a folder onto the Azure Storage System.
To get started, you will need to have a Microsoft Azure Account, create a storage account, get the connection string for it.
If you are unsure about how to proceed, check out this great introductory article: How to use Blob Storage from .NET
mobile-blob-storage-account
This is a demo connection string that you will need to add to your web.config file:
<add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=srmd1983;AccountKey=JyUOu3/iv+0UMjzI/PtoHd2JKhKx4SOSSxJcsvVp95isAZH6hKpPs/AQDOPxgVXjTNGWCYCSssgiwVVun0rlWXFgJ6A==" />

In your code, import the needed Microsoft.WindowsAzure.Storage namespace. To add this DLL, install the Azure SDK package for your version of Visual Studio and add the DLL into references.

Imports Microsoft.WindowsAzure.Storage
Imports Microsoft.WindowsAzure.Storage.Auth
Imports Microsoft.WindowsAzure.Storage.Blob

Then you will need to create a method that will do all the dirty work. The files will be uploaded in a subdirectory for each folder (in this case, the subdirectory is generated by the ClientID value).

   1:  Imports Microsoft.WindowsAzure.Storage
   2:  Imports Microsoft.WindowsAzure.Storage.Auth
   3:  Imports Microsoft.WindowsAzure.Storage.Blob
   4:  Imports System.IO
   5:  Public Class Azure
   6:  Shared Function UploadAllFilesToBlob(ClientID As String) As String
   7:  Dim err As String = ""
   8:  Try
   9:  Dim storageAccount As CloudStorageAccount = CloudStorageAccount.Parse( _
  10:  ConfigurationManager.AppSettings("StorageConnectionString"))
  11:  Dim blobClient As CloudBlobClient = storageAccount.CreateCloudBlobClient()
  12:  ' // Retrieve a reference to a container. 
  13:  Dim container As CloudBlobContainer = blobClient.GetContainerReference("uploads")
  14:  '// Create the container if it doesn't already exist.
  15:  container.CreateIfNotExists()
  16:  Dim dir As CloudBlobDirectory
  17:  dir = container.GetDirectoryReference(ClientID)
  18:  '// Create or overwrite the "myblob" blob with contents from a local file.
  19:  Dim path As String = System.Configuration.ConfigurationManager.AppSettings("SavePath")
  20:  Dim di As New DirectoryInfo(path)
  21:  For Each fi As FileInfo In di.GetFiles()
  22:  Dim fileStream = System.IO.File.OpenRead(fi.FullName)
  23:  '      // Retrieve reference to a blob named the same as the uploaded file. If the file exists, it will be overwritten.
  24:  Dim blockBlob As CloudBlockBlob = dir.GetBlockBlobReference(fi.Name)
  25:  '//create or replace
  26:  fileStream.Position = 0
  27:  blockBlob.UploadFromStream(fileStream)
  28:  fileStream.Close()
  29:  fi.Delete()
  30:  Next
  31:  Catch ex As Exception
  32:  err = "Error: " + ex.Message + "<br />" + ex.StackTrace
  33:  End Try
  34:  Return err
  35:  End Function

Windows Azure Security Whitepaper Released

After a lot of waiting, the Windows Azure Security Whitepaper has been released.

To download the latest release, check out the link below:

Windows Azure Network Security Whitepaper – FINAL

If you would like to keep your server/application secure, make sure you follow these guidelines and these Security Best Practices for Windows Azure Apps.

 

Windows Azure Security Layers
Windows Azure Security Layers

SQL Server Azure – What is my current database size?

If you are hosting on Microsoft Windows Cloud (Azure), you know that the two type of databases that you can allocate are restricted to 1GB and respectively 5GB to the personal edition and 150GB for the business edition.

If you wish to know how much space you have used so far, use the following query to return the database size:

select
sum(reserved_page_count) * 8.0 / 1024 asDatabaseSizeMB
from
sys.dm_db_partition_stats
GO

The result will be shown in MB as in the picture below:

Capture

If you wish to know which tables in your database are responsible for this database size, you can run the following query that will show the table size from largest to smallest. System tables are also included. The size is displayed in MB.

select
sys.objects.name, sum(reserved_page_count) * 8.0 / 1024
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
ORDER BY 2 DESC

Capture.JPG