14 December 2012

Six Pillars Of Microsoft Sharepoint 2010

Six Pillars Of Microsoft Sharepoint 2010
When Microsoft released SharePoint 2007, three years ago, there were lots of expectations from the product but it was far from perfect. To say that SharePoint 2007 was an improvement over 2003 version will probably be an understatement.
All the problems of Microsoft SharePoint 2007 were resolved with the introduction of Microsoft SharePoint 2010 after a long gap of three years. Microsoft has labeled SharePoint 2010 as a business collaboration platform for enterprises and the web because it opens up new domains for managing number of activities from the workplace like:
  • Document management
  • Web content management
  • Workplace collaboration
Let us now look at the pillars of SharePoint 2010:
  • Sites: Microsoft SharePoint 2010 uses different sites which help users in getting relevant information quickly. These sites can be used through internet, intranet, or extranet. It enables users to share information, data, and expertise across organizations. One of the major advantages of Microsoft SharePoint 2010 is, it allows businesses to monitor the inflow and outflow of information within the organization. The tools required for internet, intranet, and extranet remains the same. Organizations can take advantage of personalization, content management, social networking, and collaboration activities through any type of site. It also supports offline activities.
  • Communities: The new version of SharePoint allows users to work together in different ways. Microsoft has enhanced the social features of SharePoint 2007 in the current version and has made it look better. Communities allow people to collaborate in groups, share knowledge, and find information on various topics easily. Users can even take help of experts in the particular domain if they are stuck to a particular topic.
  • Content: SharePoint content shifts SharePoint 2010 from departmental solution to an enterprise solution. There has been massive improvement in content wherein users can add significant number of documents to SharePoint. They can even use external data storage options to store more data. Data is stored with proper records with complaint content management lifecycle.
  • SearchMicrosoft SharePoint 2010 has acquired FAST search server which improves the search tremendous. Now, users can not only search for content but also people. They can opt for better language options with thumbnails and previews. They can even sort out the search queries and study similar search to get relevant search results.
  • Insights: With the help of SharePoint insights, users can access information through different data sources like: dashboards, scorecards, reports and more. To help users, Microsoft has introduced Performance Point Server to SharePoint platform. It is also known as Performance Point Services for SharePoint. It helps users to discover right people and expertise to make better business decisions.
  • Composites: SharePoint, being a complete platform, helps users in creating their code solutions on premises or in cloud. Complex applications can be developed with the help of well known tools like:
    • InfoPath
    • SharePoint Designer 2010
    • Visio 2010

13 December 2012

Tips for ASP.NET Application Performance Enhancement

In the Application Web.Config File

1. Set debug=false under compilation as follows:-

<compilation defaultLanguage="c#" debug="false">

When you create the application, by default this attribute is set to "true" which is very useful while developing. However, when you are deploying your application, always set it to "false"

Setting it to "true" requires the pdb information to be inserted into the file and this results in a comparatively larger file and hence processing will be slow.

Therefore, always set debug="false" before deployment.

2. Turn off Tracing unless until required.

Tracing is one of the wonderful features which enable us to track the application's trace and the sequences. However, again it is useful only for developers and you can set this to "false" unless you require to monitor the trace logging. You can turn off tracing as follows:-

<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/>

3. Turn off Session State, if not required.

ASP.NET Manages session state automatically. However, in case you dont require Sessions, disabling it will help in improving the performance.

You may not require seesion state when ur pages r static or whn u dont need to store infor captured in the page.

You can turn off session state as follows:-

<sessionstate timeout="20" cookieless="false" mode="Off" stateconnectionstring="tcpip=127.0.0.1:42424" sqlconnectionstring="data source=127.0.0.1;Trusted_Connection=no">

While developing using Visual Studio.NET

1. Select the Release mode before making the final Build for your application. This option is available in the Top Frame just under the Window Menu option. By default, the Mode is Debug

There are several things happening when you Build/Re-Build applications in the Debug Mode. First of all, it creates an additional PDB File under your BIN directory. This holds all the Debug information.

Secondly, the Timeout is very high since you require higher time out frequency while debugging such that your process hangs on until you get to the exact break point where error is there.

So, selecting Release Mode will greatly improve the performance of the application when u deploy.

General Methods to improve the Performance

1. Disable ViewState as and when not required.
ViewState is a wonderful technique which preserves the state of your form and controls. However, its a overhead since all the information needs to be stored in the viewstate and particularly if you are building applications which target Dial Up Internet Connection Users, ViewState can make your application very slow. In case you dont require viewstate, disable it.

You can disable it at different levels ex., for Page, Control etc., by setting
EnableViewState="false"

2. Avoid Frequent round trips to the Database.
Calls made to Database can be quite expensive in terms of response time as well as resources and it can be avoided by using Batch Processing.

Make calls to Database as mininal as possible and make them last even lesser time. Use of DataAdapter wherever applicable is very useful since, it automatically opens and closes Connection whenever required and doesnt require user to explicitly open the connection.

A number of connections opened and not closed adequately can directly influence in performance slow down.

3. Avoid Throwing Exceptions.
Exceptions are a greate way to handle errors that occur in your application logic. However, throwing exceptions is a costly resource and must be avoided. Use specific exceptions and use as minimal as possible to avoid resource overhead.

For example, catching a SQLException is better when you expect only those kind of exceptions instead of a generic Exception.

4. Use Caching to improve the performance of your application.
OutputCaching enables your page to be cached for specific duration and can be made invalid based on various paramters that can be specified. The Cache exists for the duration you specify and until that time, the requests do not go to the server and are served from the Cache.

Do not assign cached items a short expiration. Items that expire quickly cause unnecessary turnover in the cache and frequently cause more work for cleanup code and the garbage collector.

In case you have static as well as dynamic sections of your page, try to use Partial Caching (Fragment Caching) by breaking up your page into user controls and specify Caching for only those Controls which are more-or-less static.

For more details regarding caching look into 
ASP.NET Caching Features

5. Use appropriate Authentication Mechanism.
The Authentication Mechanism you choose determines the cost associated with it and hence select the appropriate mechanism. An informal but useful order is as follows:-

Authentication Modes

1. None
2. Windows
3. Forms
4. Passport

6. Validate all Input received from the Users.
User Input is Evil and it must be thoroughly validated before processing to avoid overhead and possible injections to your applications. Use Client Side Validations as much as possible. However, do a check at the Server side too to avoid the infamous Javascript disabled scenarios.

7. Use Finally Method to kill resources.
In your Try..Catch.. Block, always use the Finally method to close Open connections, Open DataReaders, Files and other resources such that they get executed independent of whether the code worked in Try or went to Catch.

The Finally method gets executed independent of the outcome of the Block.

8. The String and Stringbuilder Magic.
Perhaps the most ignored type in .NET is the stringbuilder. I am sure many of us are not even aware of Stringbuilder and its advantage over string (atleast I didnt know for 1 year :))

String is Evil when you want to append and concatenate text to your string. In other words, if you are initially creating a string say s = "Hello". Then you are appending to it as s = s + " World"; You are actually creating two instances of string in memory. Both the original as well as the new string will be stored in the memory. For that matter, all the activities you do to the string are stored in the memory as separate references and it must be avoided as much as possible.

Use StringBuilder which is very useful in these kind of scenarios. For the example above, using a StringBuilder as s.Append(" World"); which only stores the value in the original string and no additional reference is created.

9. Avoid Recursive Functions / Nested Loops
These are general things to adopt in any programming language, which consumes lot of memory. Always avoid Nested Loops, Recursive functions, to improve performance.

Having said that, proper functions and call backs do increase the performance instead of having a huge chunk of lines of code in single method.

The above are just pointers to improve the performance of your application and are just illustrative. There are many more ways in which you can improve the performance of your applications. I havent dealt with IIS and SQL Server side tips to improve performance which I would explain in my forthcoming articles.

The above are my view and a collective response from various resources and you are welcome to share your views / corrections if any.

12 December 2012

SessionState in Asp.net

What is SessionState?

The session state is used to maintain the session of each user throughout the application. Session allows information to be stored in one page and access in another page and support any type of object. In many websites we will see the functionality like once if we login into website they will show username in all the pages for that they will store username in session and they will access that session username in all the pages.

Whenever user enters into website new session id will generate for that user. This session Id will delete when he leave from that application. If he enters again he will get new session Id.

We can check this one with simple example for that create one new website and open Default.aspx page and write the following code

Default.aspx


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Asp.net Session State Example in C#, VB.NET</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>SessionStateData.aspx</h3>
<table>
<tr>
<td>FirstName:</td><td><asp:TextBox ID="txtfName" runat="server"/></td>
</tr>
<tr>
<td>LastName:</td><td><asp:TextBox ID="txtlName" runat="server"/></td>
</tr>
<tr><td></td><td> <asp:Button ID="btnSubmit" runat="server" Text="Set SessionState Data"OnClick="btnSubmit_Click" /></td></tr>
</table>
</div>
</form>
</body>
</html>
Now add following namespaces in your codebehind

C# Code


using System;

After that write the following code in button click


protected void Page_Load(object sender, EventArgs e)
{

}
// Set Session values during button click
protected void btnSubmit_Click(object sender, EventArgs e)
{
Session["FirstName"] = txtfName.Text;
Session["LastName"] = txtlName.Text;
Response.Redirect("Default2.aspx");
}

What is an application object?

Application object is used to store the information and access variables from any page in application. Application object is same as session object only the difference is session object is used to maintain the session for particular user. If one user enters in to the application then session id will create for that particular user if he leaves from the application then the session id will deleted. If they again enter in to the application they will get different session id but application object is same for all users once application object is created that application object is used throughout the application regardless of user. The information stored in application object accessed throughout all the pages in application (like database connection information) and we can change the application object in one place those changes automatically reflected in all the pages.

You can create application objects in Global.asax file and access those variables throughout the application. To know about how to add Global.asax file check the post here

Add following code in Global.asax file like this


<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["UserID"] = "SureshDasari";
}
</script>
After completion of writing code global.asax file write the following code in aspx page


<html> 
<head> 
<title>Application Object Sample</title> 
</head> 
<body> 
<form id="form1" runat="server"> 
<asp:Label id="lblText" runat="server"></asp:Label> 
</form> 
</body> 
</html> 
After that write the following code in code behind like this

public void Page_Load(object sender, EventArgs e)
{
this.lblText.Text =  "UserName: " + Application["UserID"] + "<br>";
}

Now run your application you will see the application object value in your page. I hope it helps you. 

11 December 2012

10 December 2012

SQL Interview Questions

1 .
Define Primary Key?

  The primary key is the columns used to uniquely identify each row of a table.
   A table can have only one primary key.
             No primary key value can appear in more than one row in the table.
2.
Define Unique Key?

Unique key is a one or more column that must be unique for each row of the table.
It is similar to primary key. Primary key column will not accept a null. Whereas the unique key column will accept a null values.

3.
Define Foreign Key?

A foreign Key is a combination of columns with value is based on the primary key values from another table. A foreign key constraint also known as Referential Integrity Constraint.
4.
Define View?

   A View is a database object that is a logical representation of a table.
   It is derived from a table but has no longer of its own and often may be used in                            
       the same manner as a table.
          A view is a virtual table that has columns similar to a table.
   A view does not represent any physical data.
5.
Compare and contrast TRUNCATE and DELETE for a table?

Both the truncate and delete command have the desired outcome of getting rid of all the rows in a table. The difference between the two is that the truncate command is a DDL operation and just moves the high water mark and produces a now rollback. The delete command, on the other hand, is a DML operation, which will produce a rollback and thus take longer to complete.
6.
What is cursors?

Cursor is a database object used by applications to manipulate data in a set on a row-by-row basis, instead of the typical SQL commands that operate on all the rows in the set at one time.
 7.
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?

HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause. Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
8.
What is the difference between TRUNCATE and DELETE commands?

TRUNCATE is a DDL command whereas DELETE is a DML command. Hence DELETE operation can be rolled back, but TRUNCATE operation cannot be rolled back. WHERE clause can be used with DELETE and not with TRUNCATE.
9.
Define candidate key, alternate key, composite key?

A candidate key is one that can identify each row of a table uniquely. Generally a candidate key becomes the primary key of the table.If the table has more than one candidate key, one of them will become the primary key, and the rest are called alternate keys.
A key formed by combining at least two or more columns is called composite key.