DCSIMG

 Subscribe in a reader

August 2007 - Posts - Guy kolbis

August 2007 - Posts

One of the classic problems with database applications is refreshing stale data.

In a nutshell, Query Notification allows you to cache data and be notified when the data has been changed in SQL Server. Upon notification, you can then refresh your cache or take whatever action you need to.

In the following screen cast I will examine the capabilities of the notification services using the SqlDependency class.

 

 

You can download the sample code from here.

You can download the screen cast from here.

Here is a strange scenario I encountered. One of my customers complained that the number of threads is continuously increasing.

So, in order to check it, I opened the Pefmon and selected the System category that includes both processes count and the threads count. I monitored it for a while and could not detect any increase in the total threads count.

Then I opened the Objects category in the Perfmon and selected the Processes and the Threads objects. At first glance I could see that the System counters and the Objects counters are not in sync.

image

There are a few processes and threads that are missing from the System category.

When exploring the definitions for both I could see that they are just the same:

System/Objects

Threads - Threads is the number of threads in the computer at the time of data collection.

Processes - Processes is the number of processes in the computer at the time of data collection.

So, If they collect the same data and have the same definition, why are there differences???

Process

Another category that we can use to see the number of threads is the Process category with includes the Thread count counter.

I have noticed that the thread count for the Process category and the System category is the same. The explanation of the thread count counter is as follows:

Thread count - The number of threads currently active in this process.

Bottom line

That means that the total threads for all processes are equal to the System threads count and that the Objects threads count includes the total threads that are active and non-active!

When checking the thread count verify that both the active threads in the system category and the total threads in the Objects category (e.g. both the active and non active ones) does not increase over time.

DinnerNow is a fictious marketplace where customers can order food from local restaurants for delivery to their home or office. This sample is designed to demonstrate how you can develop a connected application using several new Microsoft technologies.
The demo utilizes several technologies including: IIS7, ASP.NET Ajax Extensions, Linq, Windows Communication Foundation, Windows Workflow Foundation, Windows Presentation Foundation, Windows Powershell, and the .NET Compact Framework. 
You can download the entire DinnerNow sample code from here.

In the following cast, I will be talking about the transactions for both unit tests and web tests. Transactions specifies one or more steps that are grouped together, in the web test context those steps are a bunch of URLs, where in unit test it is a bunch of code that is marked as a group.

So, why do we need it?

I will try and explain it using an example. Lets say that you have a really complicated scenario that must be executed within a unit test. The scenario requires a long initialization and couple of calls to the CRM service and to the Billing service. Because the initialization and the calls are located in the same unit test method, by default the statistics such as response time will be collected for the entire test method, however we would like to get statistics only for the calls (without the initialization) and we also would like the response time for each call and not just the total.

In this cast, I will explain the way to achieve that.

 

You can download it from here.

With enterprise library 3.1 you can create a custom exception handler that will handle the exception on hand.

First you need to create a custom exception handler. In order to implement your custom handler you must follow 3 rules:

  1. Implement the IExceptionHandler.
  2. Add a class attribute that implements the ExceptionHandlerData (e.g. CustomExceptionData).
  3. Add a constructor that receives a NameValueCollection.

Here is a sample ExceptionHandler that implements those 3 rules:

    [ConfigurationElementType(typeof(CustomHandlerData))]
    public class MyCustomHandler : IExceptionHandler
    {
        public MyCustomHandler(NameValueCollection collection)
        {
        }

        #region IExceptionHandler Members

        public Exception HandleException(Exception exception, Guid handlingInstanceId)
        {
            return new ApplicationException(exception.Message, exception);
        }

        #endregion
    }

After you created your implementation of a custom exception handler, you need to define the Custom handler in the Enterprise Library configuration tool.

image

Select your assembly that contains the custom handler class.

image

That is it, you are set to use it. 

In this screen cast, I will be show how to use the cryptography application block in order to encrypt and decrypt query string parameters. In addition I am attaching the source code for the screen cast here.

 

You can download the screen cast from here.

Screen cast walk-through

In this screen cast I will create a web site application that will contain two pages: Default.aspx and Default2.aspx. The first page will ask the user for a product id input, then it will encrypt it and perform a redirection to the second page while passing the encrypted product id. The second page will decrypt the product id and will display it on screen.

Security Helper 

The encryption and decryption will be done through a security helper that in turns will invoke methods exposed by the Cryptography application block. Here is the piece of code that invokes those operations:

public static class SecurityHelper
{
    public static string Encrypt(string string2Encrypt)
    {
        byte[] arr =
            CryptographyUtility.GetBytesFromHexString(string2Encrypt);

        byte[] arr2 =
            Cryptographer.EncryptSymmetric("RijndaelManaged", arr);

        return CryptographyUtility.GetHexStringFromBytes(arr2);
    }

    public static string Decrypt(string string2Decrypt)
    {
        byte[] arr =
            CryptographyUtility.GetBytesFromHexString(string2Decrypt);

        byte[] arr2 =
            Cryptographer.DecryptSymmetric("RijndaelManaged", arr);

        return CryptographyUtility.GetHexStringFromBytes(arr2);
    }
}

Cryptography Utility

The Cryptography Application Block includes a CryptographyUtility Class that it uses internally. I will use it to get the bytes from HexString and get the HexString back from the bytes.

Cryptographer

The Cryptographer is a Facade for using the Cryptographer application block. By using the Cryptographer Class encrypting and decrypting is very simple.

"What is pages/sec performance counter ?"

The pages/sec performance counter is a memory related counter that measures the hard page faults. A hard page fault occurs when a memory page is not in the immediate memory and needs to be fetched from the disk. It is a very important counter that can potentially help us find bottlenecks. From my experience, a good warning threshold value for the pages/sec counter would be 10 and critical threshold value would be 20.

"What is page faults/sec performance counter ?"

The page faults/sec performance counter is also a memory related counter that measures the hard page faults and the soft page faults. A soft page faults occurs when the page is located in the immediate memory but still needs to fetch it for the current process. For example, Word has opened the spellchecker, and now Outlook wishes to use it, there is no need for another call to the disk as the spellchecker is already in memory. Zero is the optimum measurement and any mesurement higher then that delays the response time, however usually the value of the page faults/sec is at least twice the size of pages/sec.