Tuesday, 26 August 2014

350 Interview Questions and Answers on .Net Framework


350 Interview Questions and Answers on .Net Framework, OOPS, ASP.Net, C#.Net, SQL Server, WCF in one place

SL NoQuestions
Q 1>What Is CLR ?
Q 2What is CLR HOST?
Q 3What is CTS?
Q 4What is CLS?
Q 5What is an Intermediate Language?
Q 6What is Just In Time Compiler?
Q 7What is Portable executable (PE)?
Q 8What is Managed Code?
Q 9What is UnManaged Code?
Q 10What is Garbage Collector?
Q 11>What is a Strong Name?
Q 12What are the steps to create Strong Name?
Q 13What are the Problems faced using Strong Name?
Q 14What is Program Database?
Q 15What is Delay Signing? 
Q 16What is an Assembly?
Q 17What are the Contents of an Assembly?
Q 18What are the Types of an Assemblies?
Q 19What is a Satellite assembly?
Q 20What are the Steps to Create Satellite Assembly?
Q 21>What is an Assembly Loader? 
Q 22What is Multi Module Assembly or Assembly Linker? 
Q 23What is an Assembly Manifest? 
Q 24What is a Metadata? 
Q 25What is a Base class in .Net?
Q 26What is Full Assembly Reference? 
Q 27What is Partial Assembly Reference?
Q 28What is an Assembly Qualified Name? 
Q 29What is ILDASM (Intermediate Language Disassembler)? 
Q 30What is Global Assembly Cache? 
Q 31>What is an Attribute?
Q 32What is Serialization & DeSerialization?
Q 33Where Serialization is used?
Q 34What are the types of Serialization available in .net?
Q 35What is Binary Serialization?
Q 36What are the Advantages & Disadvantages of Binary Serialization?
Q 37What is SOAP Serialization? 
Q 38What are the Advantages of SOAP Serialization?
Q 39What is a XML Serialization?
Q 40What are the Advantages of XML Serialization?
Q 41>What is Custom Serialization?
Q 42What is a Namespace?
Q 43What is GUID?
Q 44What is a Formatter?
Q 45What is a Binary Formatter?
Q 46What is a SOAP Formatter?
Q 47What is Reflection?
Q 48What is Thread and Process?
Q 49What are the difference between a Dll and an Exe?
Q 50What are Globalization and Localization?
Q 51>What is a Resource File?
Q 52What is Code Access Security(CAS)?
Q 53What is difference between Code Based Security and Role Based Security?
Q 54What is difference between Invoke and Begin Invoke
Q 55What is the difference between Debug and Trace?
Q 56What is a Debug version of a code?
Q 57What is a Release version of a code?
Q 58What is an IDisposable Interface?
Q 59What is Finalize block in .net?
Q 60What is Dispose block in .net?
Q 61>What is Runtime Host?
Q 62What is Connection Pooling?
Q 63What are the main parameters used by Connection Pooling?
Q 64What is Connection Pool Manager?
Q 65What is Object Pooling?
Q 66What are the Advantages of Object Pooling?
Q 67What is the Difference between Connection Pooling and Object Pooling?
Q 68What is an Indexer?
Q 69What are the important points to remember on indexers?
Q 70What is the Difference between Indexers and Properties?
Q 71>What are the different Access Modifiers available?
Q 72What are the differences between Class and Struts?
Q 73What are the Similarities between Class and Struts?
Q 74What is the term Virtual means?
Q 75What is a Sealed Class?
Q 76What is Polymorphism?
Q 77What are the Types of Polymorphism?
Q 78What is Method Overloading? Or What is Early Binding?
Q 79What is Method Overriding or What is Late Binding?
Q 80What is an Inheritance?
Q 81>What are the Types of Inheritance?
Q 82What is Multiple Inheritance?
Q 83What are the examples of Multiple Inheritance?
Q 84What are the Advantages of Inheritance?
Q 85What is an Encapsulation?
Q 86What are the examples of Encapsulation?
Q 87What is an Abstraction?
Q 88What are the examples of Abstraction?
Q 89Difference between Encapsulation and Abstraction ?
Q 90What is an Abstract Class?
Q 91>What is an Interface?
Q 92What is a difference between Abstract Class and Interface?
Q 93What is a Constructor?
Q 94What is a Constructor chaining?
Q 95What are the Types of constructors?
Q 96What is a Private Constructor?
Q 97What is a Static Constructors?
Q 98What are the features of Static Constructor?
Q 99What is a Default Constructor?
Q 100What is a COPY Constructor?
Q 101>What is a Parameterized constructor?
Q 102What is a Singleton Class?
Q 103What is a Partial Class?
Q 104What is a Partial Method?
Q 105What is a Delegate?
Q 106What is a Syntax of Single class delegate?
Q 107What are the advantages of Delegates?
Q 108What is a Multicast Delegate?
Q 109What is an Event?
Q 110What is a Hash Table?
Q 111>What is the Constructor of Hashtable?
Q 112What is an Array?
Q 113What is a Single-dimensional arrays?
Q 114What is a Multidimensional arrays?
Q 115What are Jagged arrays?
Q 116What are Mixed Arrays?
Q 117What is an ArrayList?
Q 118What is the difference between Array and Array List?
Q 119What is the Difference between Array and Collections?
Q 120What is the difference between Array.Copy and Array.Clone?
Q 121>What is a Shallow Copy?
Q 122What is a Deep Copy?
Q 123What are the different String Compare options available?
Q 124What is a Statics Class
Q 125What are the advantages of using Static Class?
Q 126List some of the main features of a Static Class?
Q 127What is a Static Member?
Q 128What is a Static Variable?
Q 129What is a Static Method?
Q 130What is a Nested Class?
Q 131>What is Shadowing or Hiding?
Q 132What are Out and Ref parameters?
Q 133What are the differences of Out and Ref Parameters?
Q 134What are the differences between String and String Builder?
Q 135Why C# is strongly typed language?
Q 136What are Imperative and Interrogative function?
Q 137What is a Collection Class?
Q 138What are the differences between Const & Readonly?
Q 139What is a Stack?
Q 140What is a Heap?
Q 141>What are Value Types?
Q 142What are Reference Types?
Q 143What are Boxing and UnBoxing means?
Q 144What is Early Binding?
Q 145What is Late Binding?
Q 146What are the different WCF binding available?
Q 147What is a BasicHttpBinding?
Q 148What is a WSHttpBinding?
Q 149What is a NetTcpBinding?
Q 150What is a WSDualHttpBinding?
Q 151>What is an ASP.NET Application and Page Life Cycle?
Q 152What are the Steps for ASP.net environment creation?
Q 153What is the ASP.NET Page Life Cycle?
Q 154What is a Directive in ASP.Net?
Q 155What are the different Validation Controls in ASP.Net?
Q 156What is the Difference between User Control and Custom Control?
Q 157What is the Difference between Client Side and Server Side Code?
Q 158What is the Difference between Server.Transfer and Response.Redirect?
Q 159What are the different IIS Isolation Levels in ASP.Net?
Q 160What are the different Authentication Modes available in ASP.Net?
Q 161>What is Windows Authentication Mode in ASP.Net?
Q 162What are the advantages and disadvantages of Windows Authentication Mode?
Q 163What is Form Authentication Mode in ASP.Net?
Q 164What are the advantages and disadvantages of Form Authentication Mode?
Q 165What is Passport Authentication Mode in ASP.Net?
Q 166What are the advantages and disadvantages of Passport Authentication Mode?
Q 167What is None Authentication Mode in ASP.Net?
Q 168What are the advantages and disadvantages of None Authentication Mode?
Q 169What are the different IIS authentications available?
Q 170What is an Event Bubbling?
Q 171>What are the differences between Machine.Config and a Web.Config files in Asp.Net?
Q 172What is an Authentication?
Q 173What is an Authorization?
Q 174What is an Impersonation?
Q 175What is Autopostback event in ASP.Net?
Q 176What is Tracing in ASP.Net
Q 177What is Scavenging?
Q 178What are Trace Listeners?
Q 179What is the difference between Respose.Write and Response.Output.Write?
Q 180What is SmartNavigation?
Q 181>What is a State Management in ASP.Net?
Q 182What are the different management objects available with Client & Server Side Stage Management?
Q 183How to Pass values between pages?
Q 184What is a View State?
Q 185What are the Benefits of ViewState?
Q 186What are the Limitations of ViewState?
Q 187What is an EnableViewState in ASP.Net?
Q 188What are Hidden Fields in ASP.Net?
Q 189What are the Benefits of Hidden Fields in ASP.Net?
Q 190What are the Limitations of Hidden Fields in ASP.Net?
Q 191>What are Hidden Frames in ASP.Net?
Q 192What are the Benefits of Hidden Frames in ASP.Net?
Q 193What are the Limitations of Hidden Frames in ASP.Net?
Q 194What is a Cookie in ASP.Net?
Q 195What are the examples of Cookie usage in ASP.Net?
Q 196What are the Types of Cookies in ASP.Net?
Q 197What are the Benefits of Cookies in ASP.Net?
Q 198What are the Limitations of Cookies in ASP.Net?
Q 199What is the relation between Cookies and Session State?
Q 200What is a Cookieless Session in ASP.Net?
Q 201>What are the Advantages of Session?
Q 202What are the Disadvantages of Session?
Q 203What is an In Proc Mode of storing sessions?
Q 204What are the Advantages of InProc Sessions?
Q 205What are the Disadvantages of InProc Sessions?
Q 206What is a State Server Mode of Storing Sessions?
Q 207What are the Advantages of State Server Session?
Q 208What are the Disadvantages of State Server Session?
Q 209What is a SQL Server Mode of Storing Session?
Q 210What are the Advantages of SQL Server mode Session?
Q 211>What are the Disadvantages of SQL Server modes?
Q 212What is Custom Session Mode in ASP.Net?
Q 213What are the Advantages of using Custom Session Mode in ASP.Net?
Q 214What are the Disadvantages of using Custom Session Mode in ASP.Net?
Q 215What is a Query String in ASP.Net?
Q 216What are the Benefits of a Query String in ASP.Net?
Q 217What are the Limitations of a Query String in ASP.Net?
Q 218What is Cross Page Posting in ASP.Net?
Q 219What is SQL Cache Dependency  in ASP.Net?
Q 220What is Global.asax in ASP.Net?
Q 221>What are the Event available in Global.asax?
Q 222What is Caching in ASP.Net?
Q 223What are the Types of Caching in ASP.Net?
Q 224How to cache different versions of the same page in ASP.Net?
Q 225What is a Fragment Cache in ASP.Net?
Q 226What are Resource Files in ASP.Net?
Q 227What are the Types of Resource Files available in ASP.Net?
Q 228What is a Local Resource File in ASP.Net?
Q 229What is a Global Resource File in ASP.Net?
Q 230What are the main tags in Web.Config file of ASP.Net application?
Q 231>What is the use of <compilation> tag in ASP.Net Web.Config File?
Q 232What is the use of <customErrors> tag in ASP.Net Web.Config File?
Q 233What is the use of <globalization> tag in ASP.Net Web.Config File?
Q 234What is the use of <httpRuntime> tag in ASP.Net Web.Config File?
Q 235What is the use of <trace> tag in ASP.Net Web.Config File?
Q 236What is the use of <identity> tag in ASP.Net Web.Config File?
Q 237What is the use of <sessionState> tag in ASP.Net Web.Config File?
Q 238What is the use of <appSettings> tag in ASP.Net Web.Config File?
Q 239What is HTTP GET in ASP.Net?
Q 240What is HTTP POST in ASP.Net?
Q 241>What is Normalization in SQL Server?
Q 242What is a De-Normalization in SQL Server?
Q 243What are the different Normalization Forms in SQL Server?
Q 244What is a Stored Procedure in SQL Server?
Q 245What are the Advantages of Stored Procedure in SQL Server?
Q 246What are the DisAdvantages of Stored Procedure in SQL Server?
Q 247What is a User Defined Functions in SQL Server?
Q 248What is a Scalar value-returning User Defined Function in SQL Server?
Q 249What is an In Line Table User Defined Function in SQL Server?
Q 250What is a Multistatement Table User Defined Function in SQL Server?
Q 251>What are the Advantages of User Defined Functions?
Q 252What are the DisAdvantages of User Defined Functions?
Q 253What is the difference between a Stored Procedure and Functions?
Q 254What is a Trigger?
Q 255What is a DML Trigger?
Q 256What is a DDL Trigger?
Q 257What is a CLR Trigger?
Q 259What are the DisAdvantages of Triggers?
Q 260What are Views in SQL Server?
Q 261>What are the Types of VIEW?
Q 262How Views ensure security of data?
Q 263List some of the common examples of views?
Q 264What are the Limitations of views?
Q 265What are Linked Servers in SQL Server?
Q 266What are the Advantages of Linked Servers?
Q 267What is a Cursor in SQL Server?
Q 268What are the steps to Create Cursor in SQL Server?
Q 269What are the Types of Cursors in SQL Server?
Q 270What are the Cursor Optimization Tips available?
Q 271>What are the Cursor Alternatives?
Q 272What are the Limitations of Cursors?
Q 273What is a SubQuery?
Q 274What are the Properties of Subquery?
Q 275What are the Types of Subquery?
Q 276What is a Correlated Subquery?
Q 277What are the Properties of Correlated Subquery?
Q 278What are the different Authentication options and Authentication Modes in SQL Server?
Q 279What is a Windows Authentication Mode?
Q 280What is a Mixed Authentication Mode(Windows Authentication and SQL Server Authentication)?
Q 281>How to Select an Authentication Mode in SQL Server?
Q 282What is an Identity?
Q 283What are INNER JOINs in SQL?
Q 284What is a LEFT OUTER JOIN in SQL?
Q 285What is a RIGHT OUTER JOIN in SQL?
Q 286What is a FULL OUTER JOIN in SQL?
Q 287What is an EQUI JOIN in SQL?
Q 288What is a CROSS JOIN in SQL?
Q 289What is a SELF JOIN in SQL?
Q 290What is a NATURAL JOIN in SQL?
Q 291>What is Log shipping?
Q 292What is an Index?
Q 293How to Create an Effective Index?
Q 294What are the Types of Indexes available?
Q 295What is the difference between Primary Key and a Unique Key?
Q 296What is the difference between Delete and a Truncate?
Q 297What is a Clustered Index?
Q 298What is a Non Clustered Index?
Q 299What is the difference between Clustered and Non Clustered Index?
Q 300What is BCP used in SQL?
Q 301>What is the use of Having and Where Clause in SQL?
Q 302What is the difference between Having and Where Clause in SQL?
Q 303What is the Local Temporary Table?
Q 304What is the Global Temporary Table?
Q 305What is the difference between @@Error and @@Rowcount ?
Q 306What is a Service Broker in SQL?
Q 307What is Database Mirroring in SQL?
Q 308What is Extended Stored Procedure in SQL?
Q 310What is an Execution Plans in SQL?
Q 311>What is Dead Lock?
Q 312What is an example of Deadlock?
Q 313How to Resolve Deadlock?
Q 314What is Live Lock?
Q 315What is an example of Live Lock?
Q 316What are the options available to Move Database between servers?
Q 317What is Replication?
Q 318What is Union?
Q 319What is Union ALL?
Q 320List some of the DBCC (Database Console Commands for SQL Server) Commands?
Q 321>What is a Full Database Backup type in SQL?
Q 322What is a Differential Database Backup type in SQL?
Q 323What is a Transactional Log Database Backup type in SQL?
Q 324What is a Log Database Backup type in SQL?
Q 325What are the advantages of NoLock in SQL?
Q 326What are the disadvantages of NoLock in SQL?
Q 327What is GRANT command in SQL?
Q 328What is REVOKE command in SQL?
Q 329What is Privileges command in SQL?
Q 330What is Cascade command in SQL?
Q 331>What is the use of RESTRICT Keyword in SQL?
Q 332What is the use of DML in SQL?
Q 333What is the use of DDL in SQL?
Q 334What is the use of DCL in SQL?
Q 335What is the use of TCL in SQL?
Q 336What is the use of Wildcards in SQL?
Q 337What is the use of Aggregate functions?
Q 338What is the use of ROLLUP in SQL?
Q 339What is the use of CUBE in SQL?
Q 340What are the Differences between CUBE and ROLLUP?
Q 341>What is the use of CUBE Operator in SQL?
Q 342What is the Difference between ROLLUP and COMPUTE?
Q 343What is the use of COMPUTE in SQL?
Q 344What is the use of COMPUTE BY in SQL?
Q 345What is the use of With TIES in SQL?
Q 346What is the use of ALL & ANY operator in SQL?
Q 347What is the use of Master Database in SQL?
Q 348What is the use of MSDB Database in SQL?
Q 349What is the use of TEMPDB Database in SQL?
Q 350What is the use of MODEL Database in SQL?
- See more at: http://www.f5debug.net/post/2012/09/17/350-Interview-Questions-and-Answers-on-Net-Framework-OOPS-ASPNet-CNet-SQL-Server-WCF-in-one-place.aspx#sthash.3K89pshw.dpuf

Satellite Assembly Example in C# (Step by Step)

Satellite Assembly Example in C# (Step by Step)

 Download source code (TestApp.zip) - 47.2 KB 

Introduction

This article is about how to understand and implement a satellite assembly.

Background

A satellite assembly is a .NET Framework assembly containing resources specific to a given language. Using satellite assemblies, you can place resources for different languages in different assemblies, and the correct assembly is loaded into memory only if the user selects to view the application in that language.
(Source: http://vb.net-informations.com/framework/satellite-assembly.htm)

Using the code

Here is the step by step procedure to create an application with a satellite assembly:
1.Create a new Windows project (say: TestApp).

2.Add a ComboBox (name it cmbLanguage) and two Labels (one label for “Select Language” and the other for Displaying the Result (name it lblMultiLangResult)) as shown below:
UI
1. Add three Resx files (string.en-US.resx, string.he.resx, and string.ar-sa.resx for English, Hindi, and Arabic, respectively). Note: For other language codes, visit: http://msdn.microsoft.com/en-us/library/ms533052(v=vs.85).aspx
2. In the resx files, enter the values shown below:
Enter Values
5. Next, open the code file (.cs file) and create the object for the resource manager at class level:
System.Resources.ResourceManager rm = new System.Resources.ResourceManager("TestApp.string", Assembly.GetExecutingAssembly());
Here in the first parameter: TestApp is the name of your Windows Application and string is the name of the Resource file part before the language code. Second parameter is the Main Assembly for the resources (for this you have to add the namespace: using System.Reflection;). 6. Write the following function for the culture:
        private void ChangeCulture(string sLangCode)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(sLangCode);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(sLangCode);
            lblMultiLangResult.Text = rm.GetString("lblResult");
        }

For the above function to run, please add the following namespaces:
using System.Threading; //For Threading
using System.Globalization; //For CultureInfo
7. On the ComboBox item change event, add the following code:
    private void cmbLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sLangCode;
            if (cmbLanguage.SelectedIndex == 0)
            {
                sLangCode = "en-US";
                ChangeCulture(sLangCode);
            }
            else if (cmbLanguage.SelectedIndex == 1)
            {
                sLangCode = "he";
                ChangeCulture(sLangCode);
            }
            else if (cmbLanguage.SelectedIndex == 2)
            {
                sLangCode = "ar-sa";
                ChangeCulture(sLangCode);
            }
        }
8. On page load, add the following line of code:
 ChangeCulture("en-US");
9. Run the application and see the output as below:
output

Points of Interest

When you look at ApplicationFolder/bin/release (check bin/debug if you are running in debug mode), there are three folders containing the same name of the DLL but each for different culture. The correct one will load when the user selects one of them.
Satellite Assembly

 

 

GROUPING SETS in SQL Server 2008

First, let's see how we rewrite simple WITH ROLLUP and CUBE queries using the new syntax.  I'll use the same schema and queries as in my previous posts:
CREATE TABLE Sales (EmpId INT, Yr INT, Sales MONEY)
INSERT Sales VALUES(1, 2005, 12000)
INSERT Sales VALUES(1, 2006, 18000)
INSERT Sales VALUES(1, 2007, 25000)
INSERT Sales VALUES(2, 2005, 15000)
INSERT Sales VALUES(2, 2006, 6000)
INSERT Sales VALUES(3, 2006, 20000)
INSERT Sales VALUES(3, 2007, 24000)
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY EmpId, Yr WITH ROLLUP
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY EmpId, Yr WITH CUBE
We can rewrite these two queries using the new syntax as:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY ROLLUP(EmpId, Yr)
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY CUBE(EmpId, Yr)
These new queries are semantically equivalent to and use the same query plans as the original queries.  Note that the new ROLLUP and CUBE syntax is only available in compatibility level 100.  The more general GROUPING SETS syntax, which I will discuss next, is also available in earlier compatibility levels.
The new GROUPING SETS syntax is considerably more powerful.  It allows us to specify precisely which aggregations we want to compute.  As the following table illustrates, our simple two dimensional schema has a total of only four possible aggregations:
Yr
2005 2006 2007 ALL
EmpId 1 GROUP BY (EmpId, Yr) GROUP BY (EmpId)
2
3
ALL GROUP BY (Yr) GROUP BY ()
ROLLUP and CUBE are just shorthand for two common usages of GROUPING SETS.  We can express the above ROLLUP query as:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr), (EmpId), ())
EmpId       Yr          Sales
----------- ----------- ---------------------
1           2005        12000.00
1           2006        18000.00
1           2007        25000.00
1           NULL        55000.00
2           2005        15000.00
2           2006        6000.00
2           NULL        21000.00
3           2006        20000.00
3           2007        24000.00
3           NULL        44000.00
NULL        NULL        120000.00
This query explicitly asks SQL Server to aggregate sales by employee and year, to aggregate by employee only, and to compute the total for all employees for all years.  The () syntax with no GROUP BY columns denotes the total.  Similarly, we can express the above CUBE query by asking SQL Server to compute all possible aggregate combinations:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr), (EmpId), (Yr), ())
EmpId       Yr          Sales
----------- ----------- ---------------------
1           2005        12000.00
2           2005        15000.00
NULL        2005        27000.00
1           2006        18000.00
2           2006        6000.00
3           2006        20000.00
NULL        2006        44000.00
1           2007        25000.00
3           2007        24000.00
NULL        2007        49000.00
NULL        NULL        120000.00
1           NULL        55000.00
2           NULL        21000.00
3           NULL        44000.00
We can also use GROUPING SETS to compute other results.  For example, we can perform a partial rollup aggregating sales by employee and year and by employee only but without computing the total for all employees for all years:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr), (EmpId))
EmpId       Yr          Sales
----------- ----------- ---------------------
1           2005        12000.00
1           2006        18000.00
1           2007        25000.00
1           NULL        55000.00
2           2005        15000.00
2           2006        6000.00
2           NULL        21000.00
3           2006        20000.00
3           2007        24000.00
3           NULL        44000.00
We can skip certain rollup levels.  For example, we can compute the total sales by employee and year and the total sales for all employees and all years without computing any of the intermediate results:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr), ())
EmpId       Yr          Sales
----------- ----------- ---------------------
1           2005        12000.00
1           2006        18000.00
1           2007        25000.00
2           2005        15000.00
2           2006        6000.00
3           2006        20000.00
3           2007        24000.00
NULL        NULL        120000.00
We can even compute multiple unrelated aggregations along disparate dimensions.  For example, we can compute the total sales by employee and the total sales by year:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId), (Yr))
EmpId       Yr          Sales
----------- ----------- ---------------------
NULL        2005        27000.00
NULL        2006        44000.00
NULL        2007        49000.00
1           NULL        55000.00
2           NULL        21000.00
3           NULL        44000.00
Note that we could also write GROUPING SETS (EmpId, Yr) without the extra set of parenthesis, but the extra parenthesis make the intent of the query more explicit and clearly differentiate the previous query from the following query which just performs a normal aggregation by employee and year:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr))
EmpId       Yr          Sales
----------- ----------- ---------------------
1           2005        12000.00
2           2005        15000.00
1           2006        18000.00
2           2006        6000.00
3           2006        20000.00
1           2007        25000.00
3           2007        24000.00
Here are some additional points worth noting about the GROUPING SETS syntax:
As with any other aggregation query, if a column appears in the SELECT list and is not part of an aggregate function, it must appear somewhere in the GROUP BY clause.  Thus, the following is not valid:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId), ())
Msg 8120, Level 16, State 1, Line 1
Column 'Sales.Yr' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
The order of the columns within each GROUPING SET and the order of the GROUPING SETS does not matter.  So both of the following queries compute the same CUBE although the order that the rows are output differs:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr), (EmpId), (Yr), ())
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((), (Yr), (EmpId), (Yr, EmpId))
If the order that the rows are output matters, use an explicit ORDER BY clause to enforce that order.
We can nest CUBE and ROLLUP within a GROUPING SETS clause as shorthand for expressing more complex GROUPING SETS.  This shorthand is most useful when we have more than three dimensions in our schema.  For example, suppose we add a month column to our sales table:
CREATE TABLE Sales (EmpId INT, Month INT, Yr INT, Sales MONEY)
Now, suppose we want to compute sales for each employee by month and year, by year, and total.  We could write out all of the GROUPING SETS explicitly:
SELECT EmpId, Month, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr, Month), (EmpId, Yr), (EmpId))
Or we can use ROLLUP to simplify the query:
SELECT EmpId, Month, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, ROLLUP(Yr, Month)))
Note that once again the correct use of parenthesis is critical.  If we omit one set of parenthesis from the above query, the meaning changes significantly and we end up separately aggregating by employee and then computing the year and month ROLLUP for all employees.
The new GROUPING SETS syntax is available in all of SQL Server 2008 Community Technology Preview (CTP) releases.

What is the difference between Web Farm and Web Garden?


What is the difference between Web Farm and Web Garden?


I have been asked this question many times by different readers of my blog. They wanted to know about the fundamentals of Web Farms and Web Garden. In this blog post, I am going to explain the exact difference between web farm and web garden, and the advantages and disadvantages of using them. I have also described how to create web garden in different version of IIS.

Overview

Visual Studio has its own integrated ASP.NET engine which is used to run the ASP.NET Web application from Visual Studio. ASP.NET Development Server is responsible for executing all the requests and responses from the client. Now after the end of development, when you want to host the site on some server to allow other people to access, concept of web servers comes in between. A web server is responsible for providing the response for all the requests that are coming from clients. The below diagram shows the typical deployment structure of an ASP.NET Web application with a single IIS.
2
Clients request for resources and IIS process the request and send back to clients. If you want to know more details on How IIS Processes the request, please read one of my articles about “How IIS Process ASP.NET Request?”.

Web Farm

This is the case where you have only one web server and multiple clients requesting for resources from the same server. But when are is huge amount of incoming traffic for your web sites, one standalone server is not sufficient to process the request. You may need to use multiple servers to host the application and divide the traffic among them. This is called “Web Farm”. So when you are hosting your single web site on multiple web servers over load balancer is called “Web Farm”. The below diagram shows the overall representation of Web Farms.
Web Farms
In general web farm architecture, a single application is hosted on multiple IIS Server and those are connected with the VIP (Virtual IP) with Load Balancer. Load Balancer IPs are exposed to external world to access. So whenever some request will come to server from clients, it will first hit the Load Balancer, then based on the traffic on each server, LB distributes the request to the corresponding web server. These web servers may share the same DB server or may be they can use a replicated server in the back end.
So, in a single statement, when we host a web application over multiple web servers to distribute the load among them, it is called Web Farm.

Web Garden

Now, let’s have a look at what is Web Garden? Both the terms sound the same, but they are totally different from each other. Before starting with Web Garden, I hope you have a fundamental idea of what an Application Pool is and what a Worker Process is. If you have already read the article, “How IIS Processes ASP.NET Request ?”, then I can expect that you now have a good idea about both of them.
Just to recall, when we are talking about requesting processing within IIS, Worker Process (w3wp.exe) takes care of all of these. Worker Process runs the ASP.NET application in IIS. All the ASP.NET functionality inside IIS runs under the scope of worker process. Worker Process is responsible for handling all kinds of request, response, session data, cache data. Application Pool is the container of worker process. Application pool is used to separate sets of IIS worker processes and enables a better security, reliability, and availability for any web application.
apppools
Now, by default, each and every Application pool contains a single worker process. Application which contains the multiple worker process is called “Web Garden”. Below is the typical diagram for a web garden application.
WebGarden Basic
In the above diagram, you can see one of the applications containing the multiple worker processes, which is now a web garden.
So, a Web application hosted on multiple servers and access based on the load on servers is called Web Farms and when a single application pool contains multiple Worker processes, it is called a web garden.

Create Web Garden in IIS 6 and IIS 7

Now, I am going to show how you can change the Number of Worker processes in both IIS 6 and IIS 7. For IIS 6, Right Click on Application Pool > Properties > Goto Performance Tab.
WebGardenIIS6
In the “Performance Tab” section, you would have one option called “Web Garden” where worker process sets to “1”, you can set the number of worker processes that you required.
For IIS 7, Right Click on Application Pool > Go To Advance Settings > In Process Model section, you will have “Maximum Worker Processes”. You can change it more than 1 to make it as a web garden.
WebGardenIIS7
In the above image, you can also check the definition of Web Garden.
You can find one of my previous articles on the basics of the same over here.

Advantages of Web Farm and Web Garden

Now, let’s have a look into the advantages of both the Web Farms and Web Gardens.

Advantages of Web Farm

  • It provides high availability. If any of the servers in the farm goes down, Load balancer can redirect the requests to other servers.
  • Provides high performance response for client requests.
  • Provides better scalability of the web application and reduces the failure of the application.
  • Session and other resources can be stored in a centralized location to access by all the servers.

Advantages of Web Garden

  • Provides better application availability by sharing requests between multiple worker process.
  • Web garden uses processor affinity where application can be swapped out based on preference and tag setting.
  • Less consumption of physical space for web garden configuration.

How to Manage Session in Web Farm Mode?

While using session, requests are distributed among different servers. By default, session mode is set to In Proc where session data is stored inside worker process memory. But, in Web farm mode, we can share the session among all the servers using a single session store location by making it Out proc (State Server or SQL Server Mode). So, if some of the servers go down and request is transferred to the other server by the Load balancer, session data should be available for that request.
sessionWebfarm
In the above diagram, you can see that we can both the IIS server sharing the same session data which is stored in out of worker process. You can read one of my previous articles “Exploring Session in ASP.NET” where I have explained how you can configure session mode for Out Process mode.

How to Manage Session in Web Garden Mode?

When we are using Web garden where request is being taken care of by different worker process, we have to make the session mode as out process session mode as described earlier. For Web Garden, we have to configure the out process within the same server but for different worker process.
webgardenSession2
While using Web garden with your application, you need make a couple of configuration settings inweb.config in <process Model> section where you need to set certain properties like cpuMask,RequestLimit, webGarden, ClientConnectCheck, etc.

Summary

When we host a web application over multiple web servers to distribute the load among them, it is called Web Farm and when one application has multiple worker processes, it is called a Web garden.
In this blog post, I have explained the very basics of what a Web Farm is and what a Web Garden is. As this blog post contains the basic information to understand the fundamentals of web farms and web garden concept, I will be posting a separate article with details configuration setting for web garden and web farm. You can read the following articles for more information:
Hope this will help you.

C# LINQ Joins With SQL

There are  Different Types of SQL Joins  which are used to query data from more than one database tables. In this article, you will learn a...