SQL Server Tip – Drop DB

Although its not a good practice to drop database when you know other’s might be still using it or someone else is connected to the db. But there are times you are tired that you can’t drop the db irrespective you think no one is logged in.

— –Kick out any user from the database so that you can safely drop the database
IF DATABASEPROPERTYEX(N’AdventureWorks’, N’Version’) > 0
ALTER DATABASE [AdventureWorks]
DROP DATABASE [AdventureWorks];

SQL Server Tip : Range to filter

Here’s a quick sql tip, using a range to filter result conditions.

–All users starting with lastname a
SELECT [FirstName],[MiddleName],[LastName]
FROM [AdventureWorks2012].[Person].[Person]
WHERE LastName like 'a%';

–All users starting with lastname a or b
SELECT [FirstName],[MiddleName],[LastName]
FROM [AdventureWorks2012].[Person].[Person]
WHERE LastName like 'a%' or LastName like 'b%';

–Users starting with lastname from range a to k
SELECT [FirstName],[MiddleName],[LastName]
FROM [AdventureWorks2012].[Person].[Person]
WHERE LastName like '[a-k]%';


Default Values

Often we see repeated lines of code checking for nulls and assigned default values. If the codes for assigning default values for non nullable properties are at more places then the chances of having properties assigned with different default values are pretty high.

Example : For DateTime field which is non nullable, you might use DateTime.MinValue or DateTime.MaxValue as the default value.

Here’s a default static class that would take care of assigning default values at one place.

public class ConvertData
public static T ConvertTo<T>(object value, object default) where T:struct
if (value.Equals(DBNull.Value))
return (T)default;
return (T)value;

Design Principles

I just finished giving my talk on User eXperience: Design Principles at philly code camp.

I had a great time attending code camp, as always its great to meet so many people, interact with like minded, passionate, driven, curious people. I did run into many who attended it from far flung places (edison(nj), delaware, pittsburgh). Keep the fire burning.

I have made the slides available and hope they will be helpful in furthering your design interests.

If you have questions/comments about my talk feel free to reach out to me. Also if you are not able to see the slides/download the slides do reach out.

Thanks again for attending my talk.

Opening new window from updatePanel

Well this should do it.

string scriptAttach = “window.open(‘ReportDisplay.aspx’, ‘Comments’, ‘width=600,height=400,top=190,left=220,titlebar=yes,toolbars=yes,

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), “MyScript”, scriptAttach, true);

Didn’t find any good solution online, so decided to post it.

Thread safe Singleton Pattern

So I ran into a very interesting scenario of singleton class initialization with different threads. I thought my implementation was thread safe only to realise otherwise in production…….(not a nice thing to know)..

Finally found a thread safe implementation of SingleTon class. For more

public class SingleTon
private static readonly object mutex = new object();
private static SingleTon instance;

private SingleTon()

public static SingleTon CreateInstance
if (instance == null)
lock (mutex)
if (instance == null)
instance = new SingleTon();
return instance;

Pittsburgh Code Camp April 2011

Today is pittsburgh code camp (April 30,2011), and I pretty excited about it. I would be presenting “WPF Data Binding: Simple to Complex” which is a very interesting and a detailed subject.

If you do a survey on people who finds the most difficult part in silverlight and wpf, hands down data binding would win. But once you know the bits i am pretty sure you would simply admire the robustness and ease provided by silverlight and wpf data binding.

As promised in my previous code camps i would be uploading my code and slide presentation prior to speaking at the code camp.

Code/Slides : http://cid-819298f11310eae7.office.live.com/browse.aspx/Code%20Camp%20Pittsburgh?Bsrc=EMSHOO&Bpub=SN.Notifications

Notify me for broken links (I know skydrive address changes…………….)

Also, people attending the pittsburgh code camp, please watch out for the next event “Pittsburgh Give Camp 2011” more at http://pittsburghgivecamp.org

Fiddler workaround for localhost

I spent another hour surfing trying everything to get fiddler to start listening to localhost. This I must have done every six months and for years.

I am just putting this in my blog as a placeholder for future reference.

Intead of http://localhost:34889/app/&#8230;,
use http://localhost.:34889/app/… (Note there is an extra dot after the keyword localhost).

and also do this in your fiddler options….

Give Camp Pittsburgh

We had our first meeting on the “Pittsburgh Give Camp” and we are going ahead with it. We are still scouting for location and most likely come up with a concrete date in a week from now. It was so heartening to see many people respond immediately on the give camp announcement made at the local PGHDOTNET meeting yesterday.

More later. I will try to keep posted on the happenings and do feel free to spread the word.

Novacc 2010 (Code & Slides)

I often think of reviewing my talks done at code camp. So far somehow i would miss them and then days would pass and I feel bad for everyone (mostly me), who could have benefitted from the code shared.

From now on, i have decided to post the slides and code block either a day in advance at my website or within a day of my presentation, so that it be useful to someone attending my talks.

Last not the least, I am very thankful to the attentive audience for yesterdays talk at code camp. I travelled more than 250 miles there to present that and was very happy to see, yes everyone did get something out of my talk(very heartening to see). The topic WPF Controls : Style and Behaviors (going to rename this talk topic from now on). Behavior is so deep down and a broader subject it cant be tackled in the stipulated time of the code camps. I might do behavior session in itself for an hour or more, because i do see many people interested in it.

Here’s the code and slide.

slide deck : Novacc Code Camp Dec 11, 2010

code : its here

Let me know if you have issues getting any of the above mentioned.