Membership and Profiler in ASP.NET

Whenever you are using Sql Membership and Profiler classes - Trying to generate reports make sure your query’s WHERE clause is using “indexed” column names at least.

Let’s look at some of the more used tables. The index of some of the tables is given below:

Table: aspnet_membership

  • Clustered Index = ApplicationID, LoweredEmail

  • NonClustered = UserID

Table: aspnet_users

  • Clustered Index = ApplicationID, LoweredUserName

  • NonClustered Index = ApplicationID, LastActivityDate

  • Primary Key = UserID

Table: aspnet_Profile

  • Clustered Index = UserID
Bottomline - try to use ApplicationID in your queries otherwise your queries, for sure, will not run over the index at all and make it slow. This comes in effect if you are expecting high volume.

Book Review: Head First Design Patterns

What an amazing book this is! It is a must read for any developer who wants to develop long term codes/projects.

The book looks at mostly the more important design patterns. The distinctive feature that stands out in this book is how it manages to make each pattern stand out against each other. It gives comparison between similar-looking patterns where necessary. It make the patterns “debate” against each other, get the birds-eye-view from “patterns guru and grasshopper discussion”, UML like “class diagrams with notes” to show how everything is gelling together.

It starts off every pattern with the basic situation and come up with a code how a normal developer would code - then give that situation a twist and show us mortal beings how to code again using a pattern! It is a perfect setup for even a novice to get it straight into his head.

The code for this book can be picked up at

Although this book is written for Java developers but it should suit C# and VB.NET. The website includes code for C# as well donated by a reader of the book.

Dynamically increase Label size [AutoSize]

Recently I had to work on a windows form where the Labels are added dynamically onto the form. Some of you may think that setting AutoSize to true would fix the problem but it works only when you already have added that Label control onto the form, not when you are adding it dynamically.

Despair not, there’s still a solution. Just create a label and set it’s text first then call this function:

If you do some testing it may not work on Compact Framework. Here’s how to get around that issue again.

Use of yield statement

It might be a little late for this to appear but I have no qualms in accepting that I have finally embraced yield statement and see it as an excellent way of writing codes.

I have had my fair share of writing small code fragments to read/process/write files and more often than that it is excel files. So I thought, there has to be an easier way than just creating common functions for Connections and processing functions - at that time yield statement came to the rescue. I have always had to read the excel file, one line after another - pretty much like a DataTable if you ask me.

The best way to put the whole process of reading the excel file is to automate reading, iterating and closing of the excel files. It is done by yield statement as I can “yield” the data of the excel through DataReader (OdbcDataReader in my case).

This way, the function is always common - it is always supposed to read the excel, iterate through it. The data that I need is always in the DataReader so I thought let’s just return the data itself! The rest of the function is pretty much normal. The biggest gain is that I don’t have to change the structure of the function. The same function can now be used for multiple excel sheets. Have a look at the code.