Remote debugging with dotMemory

dotMemory is a memory profiler from JetBrains family. With this it’s very easy to debug the remote applications. This article will give some insight on how to debug a remote deployed IIS application with below few single steps.

Install the dotMemory from By default a trial version will be installed with 5 days evaluation period. Open the path where the app is installed (default path is %localAppData%\JetBrains\Installations\dotMemory11 but this may vary based on installation type and version you install). Copy the file “” to the remote server where the site which needs to be traced is deployed. Unzip the file and run the RemoteAgent.exe in admin mode. This will open a console window similar to below. From this console window, copy the tcp url which we need it in the next step


Now open the dotMemeory exe from your local machine and select the “Remote” option. Paste the tcp url and click on connect


This will bring up all the application types that can be traced. Just select the IIS option as tha’s the one we are interested in and provide the target site name which needs the memory profiling. Click on Run and voila, its now its connected to the remotely hosted IIS site and you can take the memory snapshots from local at regular intervals to compare.


More information is available on


Creating a Website on Azure is super simple

With the latest azure tools (SDK 2.0) deploying a website on windows azure is easier than ever. With just few clicks and matter of seconds the changes will be reflected on cloud. Even the configuration made simple to use. Below are steps to follow.


A valid windows azure account (3 months free trial period works as well).

Visual Studio 2012

Windows Azure SDK 2.0 (can be installed easily with Web Platform Installer)

Step 1: Create a sample website using Visual Studio

Step 2: Login into Azure account and create a website by navigating to New->Compute->Website->Quick Create option

Step 3: Within few seconds site will be created. Just click on the site name and download the publish profile file as below.


Step 4: Come back to Visual Studio and click on Publish option. Import the above downloaded profile by navigating to Profile->Import->Import from a publish profile file.


Step 5: Click on Publish and that’s all. It will navigate to the azure site with all the code changes.


Note: With the latest update to the azure, credit card information is not a mandatory for creating a 3 months free trial account.

Using Row_Number and Over clause without table’s column name

Recently got a requirement to show the data with serial number from function which splits a delimited string and returns individual items. For instance dbo.Split(‘honda’,’bmw’) returns the honda and bmw as rows. Here the challenge is to show the row number along with the split items in the exact order in which the function returns the data without altering the function definition. Using OVER clause on the function column will give ASC/DESC order rather than what we needed. The below is the code which solves this issue without changing the existing split function.

    items [Item]

Below is the result

RowNum    Item

1             Honda

2             Bmw

3             Mazda

Hope this helps.

Custom key board mapping for Namespace organization in Visual Studio

Visual studio has lot of key board shortcuts for making the things easier. One of the mostly used feature for which IDE doesn’t have key binding is “removing unused namespaces”. I like this feature very much as it makes the code much cleaner. Normally, to make this work we need to right click on the namespaces and navigate to “organize usings ->remove and sort”. We can create a shortcut key with custom key binding as shown below. You can choose any shortcut key as per your convenience but I personally prefer Ctrl+N,O (N-Namespace, O-Organize) as this is the easy one to remember.

To create this, go to Tools->Options->environment->keyboard. By typing “organizeusing” in “Show commands containing” we can see list of IDE commands. Just select the one which ends with “OrganizeUsings.RemoveAndSort” and press the shortcut key you want to assign.

Hope this helps.

Shortcut key for entering NULL value into a table cell in SSMS

Here is a simple tip to enter null value in SQL Server Management Studio. It is a common case to enter null value into a cell. By default the cell values will be displayed with null if the table data is opened in SSMS. If we need to enter null value into a cell which has some data already into it we should explicitly type as NULL. Note that this should be in CAPS and if we give as null, SSMS assumes this null as a string value. A shortcut key for entering NULL value is ctrl+0 [ctrl key+zero].

Hope this helps

Populating Sequence values in a column to an already existing table

Recently we got a requirement to add a new identity column to an already existing table and to assign the sequential values to it. The table has thousands of rows already and manually entering the values into this column isn’t the right solution. The below query which automatically updates all the rows in a single shot has done the trick.

To do this, add the required column and update the column with the below query (change the table name and the column name as per your context) before making it as Identity column.

declare @value int=0;
update MyTable set @value=MyTableId=@value+1


Hope this helps

Dealing with many to many relationship in Entity Framework


If table has many to many relationships and it doesn’t have any additional columns other than the referenced columns, entity framework will not generate the entity by default, which causes the issue to manage the relationships.


In Entity Framework 4.0 this many to may relationship made easy which allows the automatic insertion of records in both the master and child table in a single transaction.

To describe the problem further, let us assume the below scenario.

Here the database contains Users and Roles tables. Both the tables are being referred by UserRoles. Our next step is to generate the Entities through Ado.Net Entity Data model template. After successful Entity creation, if we open the generated entities it will show only the two master tables and not the other UserRoles table. The same can be seen in model browser where all the tables are being listed in “Entities” section and only two tables in “Tables” section as below.

For a moment we might think that it’s a problem with model generator because of which the table got missed. But if we open the EDMX file in custom editor(right click on EDMX file->Open With->Automatic Editor Selector (XML)) all the properties will be listed as below.

So by this it is clear that entity generator has all the properties that are required to map the tables. It internally maintains the relationship without showing the actual table as there are no additional properties for “UserRoles” table except the primary key columns of the master tables.

Then how can we insert into this table without having entity being generated?

Entity framework will take care of that and we don’t need to write any additional queries to manage this table i.e. if we insert a user into Users table, the related record with the respective relations will be added to the UserRoles table. Here is the sample code to insert the user record and see how the records are added to both the Users and UserRoles table.

using (DemoEntities demoEnt = new DemoEntities())
User userInfo = new User()
UserId = 1,
UserName = “Super Admin”,
Password = “admin”
Role userRole = (from r in demoEnt.Roles where r.RoleId == 1 select r).Single();

The resulted table results will be as below:

Note that both the DML statements will be wrapped in “Begin transaction” to avoid the redundant data on behalf of entity framework itself.
One another problem is selecting the rows from Users table associated with specific role. How can we relate the Users and Roles as there is no common column to join these?
It is pretty simple as we have relation between User and roles table. Below LINQ query would solve the issue.

public List<User> GetUsersByRole()
using (DemoEntities demoEnt = new DemoEntities())
var userList = (from u in demoEnt.Users

from r in u.Roles

where r.RoleId == 1

select u).ToList();
return userList;

Note that if UserRoles table has at least one additional column other than the existing two columns (UserId, RoleId), this table will be generated as Entity as shown below and in this scenario everything will be same as in the normal way. In the below model we have added the “notes” column to the UserRoles table.

Thanks for reading.

Happy Coding