Tags: it interview questions

SQL Server interview questions, c# interview questions, .NET interview questions, ASP.NET interview questions

QuestPond: Interview Questions and Answers on learning ASP.NET

What is the difference between “Web farmsWeb g” and “arden”?

“Web farms” are used to have some redundancy to minimize failures and to meet heavy load demands.

It consists of two or more web server of the same configuration and they stream the same kind of contents. When any request comes there is switching / routing logic, which decides which web server from the farm, handles the request. For instance, we have two servers “Server1” and “Server2” which have the same configuration and content. Therefore, there is a special switch, which stands in between these two servers and the users and routes the request accordingly.

rout 1

Above figure explains in detail how web farm work. You can see there is a router in between which takes a request and sees which one of the server is least loaded and forwards the request to that server. Therefore, for request1 it route is server1, for request2 it routes server2, for request3 it routes to server3 and final request4 is routed to server4. So you can see because we have web farm at place server1 and server2 are loaded with two request each rather than one server loading to full. One more advantage of using this kind of architecture is if one of the servers goes down we can still run with the other server thus having 24x7 uptime.

The routing logic can be a number of different options: -

  • Round robin: Each node gets a request sent to it “in turn”. Therefore, server1 gets a request, then server2 again, then server1, then server2 again.  As shown in the above figure.

  • Least Active: Whichever node show to have the lowest number of current connects gets new connects sent to it. This is good to help keep the load balanced between the server nodes.

  • Fastest Reply: Whichever node replies faster is the one that gets new requests. This is also a good option - especially if there are nodes that might not be “equal” in performance. If one performs better than the other, then send more requests there rather than which is moving slowly?

Before we try to understand what a web garden is let’s try to understand how IIS handles processes. All requests to IIS are routed to “aspnet_wp.exe” for IIS 5.0 and “w3wp.exe” for IIS 6.0. In normal case i.e. without web garden, we have one worker process instance (“aspnet_wp.exe” / “w3wp.exe”) across all requests. This one instance of worker process uses the CPU processor as directed by the operating system.

rout 2
However, when we enable web garden for a web server it creates different instances of the worker process and each of these worker process runs on different CPU. You can see in the below diagram we have different worker process instances created which run on different CPU’s.

rout 3
In short, we can define a model in which multiple processes run on multiple CPUs in a single server machine are termed as Web garden.

How do we configure “Web Garden”?

“Web garden” can be configured by using process model settings in “machine.config” or “Web.config” file. The configuration section is named and is shown in

The following example. The process model is enabled by default (enable=”true”). Below is the snippet from config file.

<process Model
idle Timeout=”infinite”
shutdown Timeout=”0:00:05"

From the above process model section for web garden, we are concerned with only two attributes “web garden” and “cpuMask”.

WebGarden: - Controls CPU affinity. True indicates that processes should be affinities to the corresponding CPU. The default is False.

CpuMask:- Specifies which processors on a multiprocessor server are eligible to run ASP.NET processes. The cpuMask value specifies a bit pattern that indicates the CPUs eligible to run ASP.NET threads. ASP.NET launches one worker process for each eligible CPU. If web Garden is set to false, cpuMask is ignored and only one worker process will run regardless of the number of processors in the machine. If web Garden is set to true, ASP.NET launches one worker process for each CPU that corresponds to a set bit in cpuMask. The default value of cpuMask is 0xffffffff.

Below are detail steps of how to implement web garden

  • Click Start and then click Run.

  • Type calc.exe and then click OK.

  • Go to View menu, click Scientific.

  • Go to View menu, click Binary.

  • Use zero and one to specify the processors ASP.NET can or cannot use.

Use one for the processor that you want to use for ASP.NET. Use 0 for the processor that you do not want to use for ASP.NET. For example, if you want to use the first two processors for ASP.NET of a four-processor computer, type 1100.

  • On the View menu, click Decimal. Note the decimal number.

  • Open the Web.config or machine.config file in a text editor such as Notepad. The Web.config file is located in the folder where the application is saved.

  • In the Web.config file, add the process Model configuration element under the System. Web element. Before adding <process Model> to Web.config file, the user has to make sure that the allow Definition attribute in the <process Model> section of the Web.config file is set to everywhere.

  • Add and then set the web Garden attribute of the process Model element to True.

  • Add and then set the cpuMask attribute of the process Model element to the result that is determined in your calculation.

Do not preface the number with zerox because the result of the calculation is a decimal number. The following example demonstrates the process Model element that is configured to enable only the first two processors of a four-processor computer.

cpuMask=”12" />

Save the Web.config file. The ASP.NET application automatically restarts and uses only the specified processors.

See following video on ASP.NET Web.config transformation:

If you want to learn or want more on ASP.NET learning then follow site www.questpond.com
SQL Server interview questions, c# interview questions, .NET interview questions, ASP.NET interview questions

What is the difference between throw vs throw ex ?( C# Interview questions with answers)

When it comes to .NET error and exception handling this is one of the favorite .NET interview question. Below is the simplest one line answer for the above question.

“In throw the original stack exception is maintained while in throw ex the original stack exception is cleared completely.“

To understand the above one liner answer you can watch this .NET interview question video which explains throw vs throw ex in C#.

SQL Server interview questions, c# interview questions, .NET interview questions, ASP.NET interview questions

ASP.NET interview questions: - How do we enable SQL Cache Dependency in ASP.NET?

Below are the broader steps to enable a SQL Cache Dependency: -

  • Enable notifications for the database.

  • Enable notifications for individual tables.

  • Enable ASP.NET polling using “web.config” file

  • Finally use the Cache dependency object in your ASP.NET code

Enable notifications for the database.

Before you can use SQL Server cache invalidation, you need to enable notifications for the database. This task is performed with the aspnet_regsql.exe command-line utility, which is located in the c:\[WinDir]\Microsoft.NET\Framework\[Version] directory.

aspnet_regsql -ed -E -d Northwind

 -ed :- command-line switch
 -E: - Use trusted connection
 -S: - Specify server name it other than the current computer you are working on
 -d: - Database Name

So now, let us try to understand what happens in the database because of “aspnet_regsql.exe”. After we execute the “aspnet_regsql -ed -E -d Northwind” command you will see one new table and four new stored procedures created.

                                                    Figure: - SQL Cache table created for notification

Essentially, when a change takes place, a record is written in this table. The SQL Server polling queries this table for changes.

                                                                   Figure: - Stored procedures

Just to make brief run of what the stored procedures do.

“AspNet_SqlCacheRegisterTableStoredProcedure” :- This stored procedure sets a table to support notifications. This process works by adding a notification trigger to the table, which will fire when any row is inserted, deleted, or updated.

“AspNet_SqlCacheUnRegisterTableStoredProcedure”:- This stored procedure takes a registered table and removes the notification trigger so that notifications won't be generated.

“AspNet_SqlCacheUpdateChangeIdStoredProcedure”:- The notification trigger calls this stored procedure to update the AspNet_SqlCacheTablesForChangeNotification table, thereby indicating that the table has changed.

AspNet_SqlCacheQueryRegisteredTablesStoredProcedure:- This extracts just the table names from the AspNet_SqlCacheTablesForChangeNotification table. It is used to get a quick look at all the registered tables.

AspNet_SqlCachePollingStoredProcedure:- This will get the list of changes from the AspNet_SqlCacheTablesForChangeNotification table,It is used to perform polling.

Enabling notification for individual tables

Once the necessary stored procedure and tables are created then we have to notify saying which table needs to be enabled for notifications.

That can be achieved by two ways:-

  • aspnet_regsql -et -E -d Northwind -t Products

  • Exec spNet_SqlCacheRegisterTableStoredProcedure 'TableName'

Registering tables for notification internally creates triggerfor the tables. For instance, for a “products” table the following trigger is created. So any modifications done to the “Products” table will update the “AspNet_SqlCacheNotification’ table.


dbo.[Products_AspNet_SqlCacheNotification_Trigger] ON
EXEC dbo.AspNet_SqlCacheUpdateChangeIdStoredProcedure

“AspNet_SqlCacheTablesForChangeNotification” contains a single record for every table you're monitoring. When you make a change in the table (such as inserting, deleting or updating a record), the change Id column is incremented by 1.ASP.NET queries this table repeatedly  keeps track of the most recent changed values for every table. When this value changes in a subsequent read, ASP.NET knows that the table has changed.

                                                                       Figure: - Notification tables

Enable ASP.NET polling using “web.config” file

Now that all our database side is configured in order to get the SQL Cache working in the ASP.NET side we need to do some configuration in the web.config file.

We need to set two attributes in the “web.config” file:-

  • Set “Enabled” attribute to true to set the caching on.

  • Set the poll time attribute to the number of milliseconds between each poll

Below is the snapshot of the web.config file.

                                                                 Figure: - Cache dependency

Finally use the Cache dependency object in your ASP.NET code

Now comes the final step to use our cache dependency with programmatic data caching, a data source control, and output caching.

For programmatic data caching, we need to create a new SqlCacheDependency and supply that to the Cache.Insert() method. In the SqlCacheDependency constructor, you supply two strings. The first is the name of the database you defined in the element in the section of the web.config file e.g: Northwind. The second is the name of the linked table e.g: Products.

private static void CacheProductsList(List products)
{SqlCacheDependency sqlDependency = new SqlCacheDependency("Northwind", "Products");
HttpContext.Current.Cache.Insert("ProductsList", products, sqlDependency, DateTime.Now.AddDays(1),
private static List GetCachedProductList()
{return HttpContext.Current.Cache["ProductsList"] as List;}

ClsProductItem is business class, and here we are trying to cache a list of ClsProductItem instead of DataSet or DataTable.

The following method is used by an ObjectDataSource Control to retrieve List of Products

public static List GetProductsList(int catId, string sortBy)
 //Try to Get Products List from the Cache
 List products = GetCachedProductList();
 if (products == null)
 //Products List not in the cache, so query the Database layer
 ClsProductsDB db = new ClsProductsDB(_connectionString);
 DbDataReader reader = null;
 products = new List(80);
 if (catId > 0)
 //Return Product List from the Data Layer
 reader = db.GetProductsList(catId);
 //Return Product List from the Data Layer
 reader = db.GetProductsList();
 //Create List of Products -List if ClsProductItem-
 products = BuildProductsList(reader);

 //Add entry to products list in the Cache

 products.Sort(new ClsProductItemComparer(sortBy));

 if (sortBy.Contains("DESC")) products.Reverse();
 return products;


To perform the same trick with output caching, you simply need to set the SqlDependency property with the database dependency name and the table name, separated by a colon:

<%@ OutputCache Duration="600" SqlDependency="Northwind:Products" VaryByParam="none" %>

The same technique works with the SqlDataSource and ObjectDataSource controls:

<asp:SqlDataSource EnableCaching="True" SqlCacheDependency="Northwind:Products" ... />

Note:- ObjectDataSource doesn't support built in caching for Custom types such as the one in our example. It only supports this feature for DataSets and DataTables.

Just to make a sample check run the SQL Server profiler and see that does the SQL actually hit the database after the first run.

Also see following ASP.NET interview questions videos on Session VS Viewstate difference:  -

SQL Server interview questions, c# interview questions, .NET interview questions, ASP.NET interview questions

What is the use of column layout in CSS?(ASP.NET CSS interview questions with answers)

A big thanks to out sponsor’s  www.questpond.com to provide this ASP.NET CSS  interview question.

CSS column layout helps you to divide your text in to columns. For example consider the below magazine news which is one big text but we need to divide the same in to 3 columns with a border in between. That’s where HTML 5 column layout comes to help.


To implement column layout we need to specify the following:-

  • How many columns we want to divide the text in to ?

To specify column-count we need to use the below code. “webkit” and “moz-column” are needed for chrome and firefox respectively.


  • How much gap we want to give between those columns ?


  • Do you want to draw a line between those columns ?


Below is the complete code for the same.


You can then apply the style to the text by using the class attribute.


Below is a nice interview question video for quick revision.

SQL Server interview questions, c# interview questions, .NET interview questions, ASP.NET interview questions

SQL Server interview questions: - How can you increase SQL performance?

Following are tips which will increase your SQL performance: -

  • Every index increases the time takes to perform INSERTS, UPDATES, and DELETES, so the number of indexes should not be too much. Try to use maximum 4-5 indexes on one table, not more. If you have read-only table, then the number of indexes may be increased.

  • Keep your indexes as narrow as possible. This reduces the size of the index and reduces the number of reads required to read the index.

  • Try to create indexes on columns that have integer values rather than character values.

  • If you create a composite (multi-column) index, the orders of the columns in the key are very important. Try to order the columns in the key as to enhance selectivity, with the most selective columns to the left most of the key.

  • If you want to join several tables, try to create surrogate integer keys for this purpose and create indexes on their columns.

  • Create surrogate integer primary key (identity for example) if your table will not have many insert operations.

  • Clustered indexes are more preferable than nonclustered, if you need to select by a range of values or you need to sort results set with GROUP BY or ORDER BY.

  • If your application will be performing the same query over and over on the same table, consider creating a covering index on the table.

  • You can use the SQL Server Profiler Create Trace Wizard with "Identify Scans of Large Tables" trace to determine which tables in your database may need indexes. This trace will show which tables are being scanned by queries instead of using an index.

See following SQL Server interview questions videos on concept of SQL Server 8 KB page:  -

SQL Server interview questions, c# interview questions, .NET interview questions, ASP.NET interview questions

.NET interview questions: - Scenarios where serialization is used? Binary or XML serialization.

.NET interview questions: - In which scenarios we can use serialization and when to use what binary serialization or XML serialization?

Below are some scenarios where serialization is needed: -

  • Passing .NET objects across network. For example .NET remoting, web services or WCF services use serialization internally.

  • Copy paste .NET objects on clip board.

  • Saving old state of the object and reverting back when needed. For example when the user hits the cancel button you would like to revert back to the previous state.

Following are the uses of binary serialization as compared to XML serialization

  • Binary is smaller in size, so faster to send across network and also faster to process.

  • XML is more verbose, but easy to understand and human readable. But due to the XMLstructure its complex to parse and can impact performance.


Also see following .NET interview questions videos debug directive in C#:  -

SQL Server interview questions, c# interview questions, .NET interview questions, ASP.NET interview questions

ASP.NET HTML 5 interview questions on SVG and Canvas

We are thankful to www.questpond.com to provide these HTML 5 interview questions. They have awesome 500 videos ASP.NET and C# interview questions and answers which are awesome for interview preparation for .NET interviews.

What is SVG?

SVG stands for scalable vector graphics. It’s a text based graphic language which draws images using text, lines, dots etc. This makes it lightweight and renders faster.

Can we see a simple example of SVG using HTML 5?

Let’s say we want to display the below simple line using HTML 5 SVG.


Below is how the code of HTML 5. You can see the SVG tag which encloses the polygon tag for displaying the star image.


What is canvas in HTML 5?

Canvas is an HTML area on which you can draw graphics.

So how can we draw a simple line on Canvas?

  • Define the Canvas area.

  • Get access to canvas context area.

  • Draw the graphic.

Define the canvas area

So to define canvas area you need to use the below HTML code. This defines the area on which you can draw.


Get access to canvas area

To draw on the canvas area we need to first get reference of the context section. Below is the code for canvas section.


Draw the graphic

Now once you have access to the context object we can start drawing on the context. So first call the “move” method and start from a point , use line method and draw the line and then apply stroke over it.


Below is the complete code.


You should get the below output.



SQL Server interview questions, c# interview questions, .NET interview questions, ASP.NET interview questions

What is output element in HTML 5?( ASP.NET HTML 5 interview questions)

Output element is needed when you need calculation from two inputs to be summarized in to a label. For instance you have two textboxes( see the below figure) and you want to add numbers from these textboxes and send them to a label.


Below goes the code of how to use output element with HTML 5.


You can also replace “parseInt” with “valueAsNumber”.

SQL Server interview questions, c# interview questions, .NET interview questions, ASP.NET interview questions

How is the page structure of HTML 5 different from HTML 4?( HTML 5 Interview questions with answers)

We are thankful to questpond.com to provide this HTML 5 interview question with answer.

A typical web page has headers, footers, navigation, central area and side bars. Now if we want to represent the same in HTML 4 with proper names to the HTML section we would probably use a DIV tag.
But in HTML 5 they have made it more clear by creating element names for those sections which makes your HTML more readable.


Below are more details of the HTML 5 elements which form the page structure.

  • <header>: Represents header data of HTML.

  • <footer>: Footer section of the page.

  • <nav>: Navigation elements in the page.

  • <article>: Self-contained content.

  • <section>: Used inside article to define sections or group content in to sections.

  • <aside>: Represent side bar contents of a page.

SQL Server interview questions, c# interview questions, .NET interview questions, ASP.NET interview questions

WPF Interview questions with answers :-What is XAML in WPF and why do we need it?

XAML is a XML file which represents your WPF UI. The whole point of creating the UI representation in XML was write once and run it anywhere. So the same XAML UI can be rendered as windows application with WPF and the same UI can be displayed on the browser using WPF browser or Silverlight application.


We are thankful to www.questpond.com  to provide this WPF interview question with answer.
They have created 500 .NET and C# interview questions with videos , do visit them once.

Below video explain what is WPF and how they differ from Windows form