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
BEGIN
ALTER DATABASE [AdventureWorks]
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
DROP DATABASE [AdventureWorks];
END;
GO

Advertisements

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;
}
else
{
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,
scrollbars=yes,status=yes,resizable=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
{
get
{
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