Wednesday, 27 March 2013

SQLServer 2012 – New Features Useful for Developers

SQL Server 2012 have included varied improvements and great features in the form of new tools, coding and programmability enhancements, and even new improvements to the underlying SQL Server engine for developers. Some of the advantages are as follows:

Multi Monitor Support

  • SSMS 2012 picks up Visual Studio 2010's vastly improved multi-monitor support.

Snippets
  •  SSMS 2012's snippets feature is a significant productivity boon for developers.
  •  SSMS 2012 provides the ability to leverage code snippets within SSMS. This capability is something that has been lacking within Visual Studio over the past half-decade. SSMS snippets are injected by means of pulling up a snippets "menu" that can be accessed via the Edit, IntelliSense, Insert Snippet menu option -- or via a similar Surround With menu option.
  • Both of these menu options, of course, can be accessed via hotkeys (Ctrl+K, X and Ctrl+K, S), and the existing library of snippets available is quite large and helpful out of the box.
  •  When it comes to customizing and managing snippets, the Tools, Code Snippets Manager option provides paths to existing snippets along with the option to add or remove snippets as needed.

Improvements for Visual Studio 2010
  • A significant tooling change for developers is that with SQL Server 2012 is now BIDS ceases to exist
  • BIDS was always a source of unending frustration for developers who wanted to do .NET development and manage any form of BI (or SS*S) projects as well -- simply because of all of the versioning problems that continued to plague BIDS throughout its history.
This retirement means that it's now possible with SQL Server 2012 to directly create and manage all BI-related projects directly within Visual Studio 2010. With this there is some bad news as well.. the bad news is that age-old compatibility problems still exist in the sense that if you want support for managing BI-related projects in Visual Studio 2010, you have to uninstall Visual Studio (if it's already installed) and then re-install it after you install SQL Server 2012. However, an easier way to get BI-related project templates is to just install SSDT.


Programmability Enhancements

T-SQL gets a THROW statement –

 For SQL Server developers, the lack of a T-SQL THROW statement has always been difficult. SQL Server 2012 has addressed this lack—Howevrer,  there are a number of limitations as to how this statement can be used. Likewise, as cool as this new feature is, just remember that RAISERROR (despite its archaic spelling) still provides a number of powerful features that THROW (and PRINT) simply don't offer

T-SQL finally supports built-in pagination
  • SQL Server 2012 finally introduces full-blown, first-class support within T-SQL for pagination, as shown in below Figure.
  • Note, pagination is technically a feature or argument of the ORDER BY clause -- and that Microsoft actually recommends using OFFSET and FETCH as a replacement for TOP. 

Figure: Built-in pagination with support for OFFSET and FETCH via the ORDER BY clause
PPP



Support for sequences-

Another new feature that SQL Server 2012 provides is support for sequences. A sequence can best be described as being a bit like an IDENTITY "object" because it behaves just like an IDENTITY column without actually being a column. Developers can create sequences, query them for one or more IDs (which are returned in sequence), and then do whatever they want with those supplied IDs prior to INSERTing them into a table that needs a unique, sequentially incrementing, identity value, as shown in Figure

Figure: Example of a simple sequence in operation 
PPP



Discontinued and Deprecated Features

Of course, with every new release of SQL Server, there are also a few features and bits of syntax that are either removed outright or are slated for later removal. Happily, with SQL Server 2012, the list of deprecated and removed features is relatively small. This, in turn, means that SQL Server 2012 does a great job of providing developers with new features -- with very little worry or concern for negative problems of backward compatibility.

About Author:
Dhairut Dholakia is technology lover and is important part of Systems Plus technology Think Tank. He works in systems Plus and actively contributes to technology. He can be contacted at: dhairut.d@spluspl.com

Monday, 18 March 2013

Profiling your .NET code

Profiling gathers information about an executing application, allowing you to determine those improvements that are required in your application. Profiling is overlooked or not performed on applications despite the fact that it can have a massive benefit to the performance and scalability of these applications. This article starts with a "Top 10" list of reasons why you should give careful consideration to the task of profiling your .NET code. It then introduces the two basic tools that will get you started with this task, namely the CLR Profiler and Perfmon.

Ten reasons why you should bother profiling your .NET code

1) Focus on portions of your .NET code that really require attention
Profiling allows you to focus on critical sections of your .NET code. When you have a very large application it is very difficult to identify areas in your .NET code that require improvement. Profiling your application will pinpoint .NET code sections that really require improvement or tuning.
2) Identify code blocks with performance issues
Performance is a very hard thing to measure and trace. The task of identifying code blocks or methods that have performance issues is tedious. Profiling your .NET code helps you to identify those code lines, blocks or methods that require performance improvement.
3) Compare alternative approaches
During your development, you might come across alternate ways of achieving a task. For any given task you might have two different implementations that you wish to compare, in order to find out which implementation is better in terms of performance, scalability, and resource usage. By comparing your different implementations with a profiler, you can select the most efficient code block.
4) Get accurate code execution response times
Often, when you examine the performance of your application, you will want to find out how long a line of code, or a block of code, or a method, takes to execute. By profiling your .NET code you can get accurate execution times.
5) Avoid guessing performance issues
Have you ever looked at your application and felt that it is executing slower than usual? You cannot just go by your instinct and start making changes to your application. By profiling your application, you can confirm whether performance issues exist in your application, and where those issues are.
6) Visualize performance and memory usage
A visual depiction of execution times and memory usage for your application helps you to make informative decisions very quickly. Once you have the means to see a graph of the execution times or memory usage, it is much easier and quicker to understand issues and fix them.
7) Track the lifecycle of your .NET objects
You might be using a resource intensive object in your .NET code. Tracking the lifecycle of your .NET object will allow you to make optimizations in your code. For example you might be creating the resource intensive object too early in your application. Profiling will uncover these issues.
8) Avoid unnecessary loading or initialization of your program
During development of your application you might have had some tests that are loaded and initialized. Prior to deployment of your application you will want to ensure that any unnecessary loading or initialization is removed. It would be very difficult to track such portions of your application without profiling it.
9) Optimize your looping constructs in .NET
Looping constructs are a common source of performance issues. Profiling your code allows you to understand and eliminate unnecessary loops within your looping constructs. Improving your looping constructs in turn will improve the overall performance of your .NET application.
10) Identify memory leaks in your application
Memory leaks in your application can be very difficult to identify. Profiling your .NET code allows you to identify any unnecessary memory usage and therefore optimize the memory usage in your .NET application.


How to profile your .NET code
Now that we have looked at some compelling reasons to consider profiling, let us look at a couple of the basic, free tools that allow you to profile your .NET code.

CLR Profiler
The CLR Profiler is a free application that allows you to profile Windows applications, ASP.NET applications or services. You can download the CLR profiler from here. Once you have downloaded it, you can extract it and run the CLRProfiler.exe. When you run the CLR profiler your code will appear to execute slower than usual since your code will be instrumented to analyze the performance.
Let us create a simple Windows application and then analyze it using the CLR Profiler. You can create the following method as part of your application and invoke it (you can download Visual C# 2008 Express Edition from here ):
C# Code
public void CodeToProfile()
{           
string str = string.Empty;
for ( int i = 0; i < 2000; i++)
{
str = str + "|" + i.ToString();
}
MessageBox.Show(str);
}


Start the CLR profiler, and you will see the following initial screen:

Selecting "Allocations and Calls", allows us to profile the methods as well as memory usage. You can click on "Start Application" and select the Windows application we created. The CLR profiler will load the Windows application and you can execute it to call the method we wrote earlier.
When you close the Windows application, the performance of the application is analyzed and a summary screen is presented:


You can drill into any specific areas on the performance. For example, if you want to find out how much memory was allocated on the Heap, you can click on the "Histogram" for Allocated Bytes, in the summary screen. The View menu in the main CLR profiler screen also includes menu items for the options you see on the summary screen for your application.



The above screen shows that a large amount of memory is being allotted for the strings, since we are doing concatenation and each concatenation is creating a new string instance. Let us save the current profile results.
To fix the above problem, let us replace the string concatenation with a StringBuilder. So, our new method implementation looks as follows:
C# Code
public void CodeToProfile(){
StringBuilder str = new StringBuilder();
for ( int i = 0; i < 2000; i++)
{
str.Append( "|").Append(i.ToString());
}
MessageBox.Show(str.ToString());
}
Let us go through the steps of profiling the application again. After profiling, the "Histogram by Size for Allocated Byes" screen looks as follows:



You can see that the memory allotted is considerably reduced using an alternate implementation.

Using PerfMon
Another tool you can use to analyze the performance of your application is the PerfMon (Performance Monitor). This tool is available as part of Windows Administrative tools and contains performance counters to analyze various aspects of your application. For example, in Windows XP, navigate to Administrative tools and select Performance. This will start the Microsoft Management Console for PerfMon.



The initial view shows the System Monitor monitoring a few performance counters for the entire system. To monitor .NET application-specific performance, click on the "new" option on the toolbar. This will clear the current view and you can add performance counters for the specific aspects for your application
To add a performance counter, click on "Add". This brings up the "Add Counters" interface that allows you to add a performance counter. PerfMon contains a lot of counters that are specific for .NET applications. For example, to monitor the memory allocated on the heap for your .NET objects, you can select the .NET CLR memory Performance object and then select the "# Bytes in all Heaps" performance counter. If you want to monitor all .NET CLR memory related counters, you can select "All counters". You can also select a specific instance or application for which you want to monitor the .NET CLR memory.



This creates a graph that will show any spikes in the view when you execute your application. This allows you to graphically visualize the memory usage while you interact with your .NET application. If there are any unusual spikes while executing your application, you can try improving your code and running the application again while monitoring the performance in PerfMon.



Other than the .NET CLR specific performance counters, you also get a lot of counters that are specific to ASP.NET web applications. For example, you can have a view that shows the total requests that failed for the ASP.NET application against the total requests received, and also monitor how specific resources such as memory were used when the number of requests is high.

Conclusion
Profiling your .NET code is a very important task in ensuring your application performs as expected. This article shows 10 reasons why you should seriously consider profiling your .NET code and then explains how to use the CLR profiler and the PerfMon tools.


About Author:
Nirmal Doshi is budding technology geek, who helps Systems Plus with his creativity and research on technology He works in systems Plus and actively contributes to technology.He can be contacted at: nirmal.d@spluspl.com

Monday, 11 March 2013

Leadership Practice

"Change is inevitable"
The above line would have been heard by each and everyone. This is true in real life and with the growth, change in mind set, competition, increase in competency level of an average person, we do change or are part of change in each aspect of life. This is true even in Leadership. Here I have collected 10 points which should be changed or rather removed from the "Leadership Practice" which we have been following for years. 

Business owners certainly have a long way to go, especially in more established companies where old practices die hard. By creating a company with a clear purpose and values, you'll find your employees connect themselves to something bigger, and that increases productivity.  In other words, a culture of engagement leads to greater customer loyalty, and better financial success.

Remove or throw away following from your leadership Practice.
  1. Micro-management, or the need to control every aspect of your company is outdated. Empowerment, the ability to give your people some rope--even rope to make mistakes without blame. Empowerment is the Key now.
  2. Management by walking around the office; it is no longer enough to be visible. What is now happening is : Leadership by watching and listening, engaging in conversation, implementing the ideas presented to you, and distributing the results.
  3. Pretending you know everything. You don't have all the answers, so why try to make people think you do? This practice is gone now and what is in is: Knowing your leadership team members and trusting them. Choose great people who have the right skills and fit the culture.  And get out of the way.
  4. No mistakes, or a "no tolerance policy" some still think works, but it does not. Today we are  Learning from mistakes, or being the first to admit an error.
  5. The balance sheet drives the business, and informs all other decisions is out and what is in is  People drive the business, boosting customer loyalty, and profit.
  6. Job competency is sufficient. Do the job asked, and you'll survive. This now history. Need of today is  Recruit "A" players who will go the extra mile. They're out there.
  7. Out: Invest in technology to increase productivity. In: Invest in people.
  8. Out: Demand change; be very specific about what you want and when. In: Nurture change; your people can come up with the best ideas and you can give them credit for it.
  9. Out: Fried food in the cafeteria. In: Wellness in the workplace.
  10. Out: Incentives; pay employees more money and they'll do more. In: Rewards; being valued matters more than money.
Think... For all the leaders and all those which aspire to be leaders

About Author:
Asheesh Vashisht  is loves to mold technology with soft skill practice. He works in systems Plus and actively contributes to technology and Soft skill blogs.
To more of interesting topics written by Asheesh Vashisht, follow http://asheeshv.blogspot.in/