Monday, December 29, 2014

How to make a database copy from production to staging server in Azure

On the same server

We need 1 user name with its password on staging database and production database. It is 1 time process only. If same user is not present in source and destination database then we can not create backup of database.
Note: It is required only if your Source and destination database is present on different server. If they are present in same server then you need to execute only following query with your respected values.
1.       Connect to destination server (Here Staging DB) “master” database with productions username and pwd  because we need to have same username with password on source and destination DB.

2.       Execute the following command:
a.       CREATE DATABASE [NEWDATABASENAME] AS COPY OF [SOURCE_SERVERNAME].[SOURCEDATASE]
b.      IMP: Replace the NEWDATABASENAME, SOURCE_SERVERNAME and SOURCEDATASE with correct names

To track progress you can run following command or you can connect to Azure portal and check the progress in database tab

3.       Execute: Select *  from sys.dm_database_copies, this will give you the stats of the % of database copied

hHappy Coding !!


How to rename a SQL Azure database?

1. Connect to your Database
2. Select Master Database
3. Type following Query

Syntax:
alter database <old-database-name> modify name = <new-database-name>

Description:
<old-database-name> is your old DB name
<new-database-name> is your new DB name
Note: Don't use single or double quotes around DB Name

Example:
alter database MyStudent modify name = StudentMaster


Your DB name is changed :)

Happy Coding !!

Thursday, April 10, 2014

Error Logging using Log4Net for azure and normal applications


Following are good links for error logging using Log4Net

For Normal Applications:
http://geekswithblogs.net/MarkPearl/archive/2012/01/30/log4net-basics-with-a-console-application-c.aspx

For Azure Applications:
http://www.kongsli.net/nblog/2011/08/15/log4net-writing-log-entries-to-azure-table-storage/

Wednesday, April 9, 2014

Azure Active Directory integration in asp.net MVC

Azure Active Directory integration in asp.net MVC


Pre- requisite:

1. Visual Studio 2012 Professional or Visual Studio 2012 Ultimate
2. Identity and Access Tools for Visual Studio 2012
3. Azure Subscription

Step 1:

 You need to create Active directory in your Azure subscription. You need to register your application in azure subscription.
 Active directory is called as tenant. Your users from your active directory(tenant) are able to login to your application.
 other users are not able to login. To make other users access available then you need to implement step 3 as well.
Details explained in following link.
 http://msdn.microsoft.com/en-us/library/windowsazure/dn151790.aspx

Step 2:

You can achieve following:
 1. Getting full user details
 2. Creating and Updating Users
 3. Getting a list of groups
 4. Updating group membership
Details explained in following link.
 http://msdn.microsoft.com/en-us/library/windowsazure/dn151791.aspx


Step 3:

 If you want to allow access to other user from your organization. then you need to implement multiple tenant(active directory) in your application.
 So other user will be able to login to your application.
Details explained in following link.
 http://msdn.microsoft.com/en-us/library/windowsazure/dn151789.aspx


Happy Coding !!

Monday, April 7, 2014

Azure: Building and Packaging Virtual Applications within Azure Projects

Check following links for proper deployment. Which deploys published code instead of complete code solution.

http://kellyhpdx.wordpress.com/2012/04/11/deploying-multiple-web-applications-to-a-single-azure-instance-and-applying-web-config-transforms-correctly/


http://blogs.msdn.com/b/davidhardin/archive/2013/01/18/building-and-packaging-virtual-applications-within-azure-projects.aspx

Thursday, January 23, 2014

Windows Azure: Upload and Download Functionality- upload/download image to blob


Following class is useful to download or upload image from blob. Provide necessary parameters to function.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Configuration;
using Microsoft.WindowsAzure;
using System.IO;
using Microsoft.WindowsAzure.ServiceRuntime;
namespace AzureDemo
{
    public class AzureBlobManager
    {
        public string uploadFilesToAzureBlob(FileUpload PostedFile, string FileName, string containerName, Guid userid)
        {
            string blobURLs = string.Empty;
            try
            {
                // Retrieve storage account from connection string.
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
                // Create the blob client.
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                // Retrieve a reference to a container.            
                CloudBlobContainer container = blobClient.GetContainerReference(containerName);
                // Create the container if it doesn't already exist.
                container.CreateIfNotExists();
                if (PostedFile.PostedFile.ContentLength > 0)
                {
                    System.IO.Stream inputStream = PostedFile.PostedFile.InputStream;
                    inputStream.Position = 0;
                    byte[] myBinary = new byte[PostedFile.PostedFile.ContentLength];
                    //PostedFile.InputStream.Read(myBinary, 0, (int)PostedFile.ContentLength);
                    using (var binaryReader = new System.IO.BinaryReader(inputStream))
                    {
                        myBinary = binaryReader.ReadBytes(PostedFile.PostedFile.ContentLength);
                    }
                    // Retrieve reference to a blob named "myblob".
                    CloudBlockBlob blockBlob = container.GetBlockBlobReference(string.Concat(userid, "_", PostedFile.FileName));
                    // Create or overwrite the "myblob" blob with contents from a local file.                    
                    //blockBlob.UploadFromStream(PostedFile.PostedFile.InputStream);
                    blockBlob.UploadFromStream(new System.IO.MemoryStream(myBinary));
                    // blockBlob.UploadFromStream(PostedFile.PostedFile.InputStream);
                    blobURLs = blockBlob.Uri.ToString();
                }
            }
            catch (Exception ex)
            {
                //HandleException.HandleExceptionLog(ex);
            }
            return blobURLs;
        }

//Directly reads from blob and sends it to user
        public void DownloadFileFromBlob(string fileName,string containerName)
        {
            CloudStorageAccount account = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
            CloudBlobClient blobClient = account.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
            MemoryStream memStream = new MemoryStream();
            blob.DownloadToStream(memStream);
            HttpContext.Current.Response.ContentType = blob.Properties.ContentType;
            HttpContext.Current.Response.AddHeader("Content-Disposition", "Attachment; filename=" + fileName.ToString());
            HttpContext.Current.Response.AddHeader("Content-Length", blob.Properties.Length.ToString());
            HttpContext.Current.Response.BinaryWrite(memStream.ToArray());
        }
    }
}

Happy Coding!! 

Friday, October 25, 2013

IE11 and Windows 8.1 : Solution for __doPostBack and Ajax not working

When we tested our website against latest IE 11 browser then we came to know that our website is not working properly against IE 11 browser.

I tried to find out on the solution for this issue and i found out following ways which will help us to resolve issue on IE 11 browser.

​Following Steps are performed to fix IE 11: ajax and __dopostback issues:
You can upgrade to .net framework 4.5 which will help us to resolve issue. If you can not update then we have some temporary alternative solution.

There are 2 solutions:

1. Site Level Fix:

Nuget has provided an update for the browser, you can execute the co

   step 1: Perform Steps from following links
        http://www.nuget.org/packages/App_BrowsersUpdate/
  
   step 2: In ie.browser add mentioned settings from following link

In your project, add to (or create as) App_Browsers/ie.browser, the following:

<!-- Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko -->
<browser id="IE11Preview" parentID="Mozilla">
    <identification>
        <userAgent match="Trident/(?'layoutVersion'\d+).*rv:(?'revision'(?'major'\d+)(\.(?'minor'\d+)?))" />
        <userAgent nonMatch="MSIE" />
    </identification>

    <capabilities>
        <capability name="browser"              value="IE" />
        <capability name="layoutEngine"         value="Trident" />
        <capability name="layoutEngineVersion"  value="${layoutVersion}" />
        <capability name="isColor"              value="true" />
        <capability name="screenBitDepth"       value="8" />
        <capability name="ecmascriptversion"    value="3.0" />
        <capability name="jscriptversion"       value="6.0" />
        <capability name="javascript"           value="true" />
        <capability name="javascriptversion"    value="1.5" />
        <capability name="w3cdomversion"        value="1.0" />
        <capability name="ExchangeOmaSupported" value="true" />
        <capability name="activexcontrols"      value="true" />
        <capability name="backgroundsounds"     value="true" />
        <capability name="cookies"              value="true" />
        <capability name="frames"               value="true" />
        <capability name="javaapplets"          value="true" />
        <capability name="supportsCallback"     value="true" />
        <capability name="supportsFileUpload"   value="true" />
        <capability name="supportsMultilineTextBoxDisplay" value="true" />
        <capability name="supportsMaintainScrollPositionOnPostback" value="true" />
         <capability name="supportsVCard"        value="true" />
        <capability name="supportsXmlHttp"      value="true" />
        <capability name="tables"               value="true" />
        <capability name="supportsAccessKeyAttribute"    value="true" />
        <capability name="tagwriter"            value="System.Web.UI.HtmlTextWriter" />
        <capability name="vbscript"             value="true" />
        <capability name="revmajor"             value="${major}" />
        <capability name="revminor"             value="${minor}" />
    </capabilities>

</browser>


Once you perform above mentioned steps, your issue will be resolved.

2. Machine Level Fix:


   Step 1: Download patch from following link.
     http://support.microsoft.com/kb/2836939
   Step 2: install patch

   Main Source: http://www.hanselman.com/blog/IE10AndIE11AndWindows81AndDoPostBack.aspx

With the help of above fixes you can fix issue.

Happy Coding!!