Skip to main content

Posts

Showing posts from February, 2010

SQL Server: GETDATE() & GETUTCDATE() & different time zones

Most of us will use GetDate() function for providing default value in SQL server columns. This function Returns the current database system timestamp as a   datetime   value without the database time zone offset. This value is derived from the operating system of the computer on which the instance of SQL Server is running. This works perfectly if you don’t have to show reports and such stuffs for users from different time zones. In case you want to store time independent of time zones in some universal format; what will do? Well there is GetUtcDate() function for you. This function will return then UTC date based on the setting of the server on which SQL server is installed. I executed the following function & I got the two different date output values. SELECT  GETDATE() AS Expr1, GETUTCDATE () AS Expr2 2/28/2010 1:27:17 PM ,  2/28/2010 7:57:17 AM SQL Server 2008 SQL Server 2008 has two new DataTypes: date & time You can use them to retrieve the date &

ASP.net - Http handlers - Generic Hander

An HTTP Handler is a . NET class that executes whenever you make a request for a file at a certain path. Each type of resource that you can request from an ASP. NET application has a corresponding handler. When you request an ASP. NET page, the Page class executes. The Page class is actually an HTTP Handler because it implements the IHttpHandler interface. Other examples of HTTP Handlers are the TraceHandler class, which displays applicationlevel trace information when you request the Trace.axd page and the ForbiddenHandler class, which displays an Access Forbidden message when you attempt to request source code files from the browser. Similarly you can create your own HTTP handlers for acting on any requests received at webserver. Generic Hander Add a generic handler by right clicking on the project explorer > Add> new item> select Generic Handler. A new file with ASHX extension is created. Here is a sample code which I got from Steven Walthers book. This handler cr

C# Thread Synchronization

Multithreading enables you to have several threads of execution running at the same time. But in this case there is a risk of one thread trying to access resource when another tread is working on the resource. In short they all compete for the same set of resources, so there must be a mechanism to ensure synchronization and communication among threads. You can use the following ways to synchronize your threads: The Interlocked class     // Summary:     //     Provides atomic operations for variables that are shared by multiple threads.     public static class Interlocked     { public static int Decrement( ref int location) public static long Decrement( ref long location); public static int Increment( ref int location);         //         // Summary:         //     Increments a specified variable and stores the result, as an atomic operation.         //         // Parameters:         //   location:         //     The variable whose value is to be incremented.   

C# Thread Synchronization

Multithreading enables you to have several threads of execution running at the same time. But in this case there is a risk of one thread trying to access resource when another tread is working on the resource. In short they all compete for the same set of resources, so there must be a mechanism to ensure synchronization and communication among threads. You can use the following ways to synchronize your threads: The Interlocked class     // Summary:     //     Provides atomic operations for variables that are shared by multiple threads.     public static class Interlocked     { public static int Decrement( ref int location) public static long Decrement( ref long location); public static int Increment( ref int location);         //         // Summary:         //     Increments a specified variable and stores the result, as an atomic operation.         //         // Parameters:         //   location:         //     The variable w