Sunday, February 15, 2009

Asp .net job interview question

Write a custom function in c-sharp. The custom function parameters should be an instance of a dropdownlist, an xml file and a string.
1. The function should be capabale of populating the passed in dropdownlist.
2. The first item in the dropdownlist should be the passed in string parameter.
3. The data for the dropdownlist comes from the passed in XML file.

The idea is to create a custom function which can be reused through out the project for populating any dropdownlist on any web page. You have 20 minutes to code, test and demonstrate.

The sample code for custom function is shown below. For this example to work drop the XML file in the root folder of the web application.

protected void Page_Load(object sender, EventArgs e)
PopulateDropdownlist(DropDownList1, "DropDownListSource.xml", "Select State");

public void PopulateDropdownlist(System.Web.UI.WebControls.DropDownList DropDownListObjectToBePopulated,string XMLFilePath, string InitialString)
DataSet DS = new DataSet();
if (InitialString != string.Empty)
ListItem LI = new ListItem(InitialString, "-1");
foreach (DataRow DR in DS.Tables["State"].Rows)
ListItem LI = new ListItem();
LI.Text = DR["StateName"].ToString();
LI.Value = DR["StateCode"].ToString();
catch(Exception Ex)

The XML file that has the data for the dropdownlist is as shown below.



North Carolina



Explanation of the code:
PopulateDropdownlist function has 3 parameters. DropDownList to be populated, the path of the XML file which has the data for the dropdownlist and the initial string.

2. Create an instance of DataSet. In our example the instance is DS.
DataSet DS = new DataSet();

3. Read the XML data into the dataset instance using ReadXml() method. Pass the path of the XML file to ReadXml() method. We used Server.MapPath() method to return the physical file path that corresponds to the specified virtual path on the web server.

4. We now have the data from the XML file in the dataset as a DataTable.

5. Check if the InitialString is empty. If not empty create a new ListItem object and populate the Text and Value properties. Then add the listitem object to the dropdownlist.
if (InitialString != string.Empty)
ListItem LI = new ListItem(InitialString, "-1");

6. Finally loop thru the rows in the DataTable and create an instance of ListItem class. Populate the Text and Value properties to StateName and StateCode respectively. Finally add the ListItem object to the dropdownlist.
foreach (DataRow DR in DS.Tables["State"].Rows)
ListItem LI = new ListItem();
LI.Text = DR["StateName"].ToString();
LI.Value = DR["StateCode"].ToString();

7. Drag and drop the dropdownlist on a webform. Call the PopulateDropdownlist() custom function in the Page_Load event handler. When you call the custom function pass the dropdownlist to be populated, XML file path and the initial string.
protected void Page_Load(object sender, EventArgs e)
PopulateDropdownlist(DropDownList1, "DropDownListSource.xml", "Select State");

ASP .net interview question

Please write a sample program that parses the string into a series of substrings where the delimiter between the substrings is "^*!%~" and then reassembles the strings and delimiters into a single new string where each of the substrings is in the reverse order from the original string. The method must return the final string.

Original String:
Token A^*!%~Token B^*!%~Token C^*!%~Token D^*!%~Token E

Output String:
Token E^*!%~Token D^*!%~Token C^*!%~Token B^*!%~Token A

The code sample below shows how to solve the above question:
using System;
using System.Text;
namespace GenericsSample
class Program
static void Main()
string strOriginalString = "Token A^*!%~Token B^*!%~Token C^*!%~Token D^*!%~Token E";
string[] strSeperator = new string[1];
strSeperator[0] = "^*!%~";

string[] strArrayIndividualStrings = strOriginalString.Split(strSeperator, StringSplitOptions.RemoveEmptyEntries);

int intLengthOfStringArray = strArrayIndividualStrings.Length;

StringBuilder sbOutputString = new StringBuilder();
for (int i = (intLengthOfStringArray - 1); i >= 0; i--)
sbOutputString.Append(strArrayIndividualStrings[i] + strSeperator[0]);
Console.WriteLine("Original String : " + strOriginalString);
Console.WriteLine("Output String : " + sbOutputString.ToString());

Explanation of the above sample program:
We take the original string into a string variable strOriginalString. I named this variable as strOriginalString. str indicates that the variable is of string datatype. This will give a good impression to the person who reviews your code bcos you are following the coding standards.

2. I then store the string delimiter "^*!%~" in strSeperator variable. strSeperator is of string array data type. This is bcos the split function expects string array or character array as seprator.

3. I then split the strOriginalString into a string array using the split function.

4. I created a variable sbOutputString to store the Output string. sbOutputString data type is StringBuilder.

5. I then loop thru the array from the highest index to 0 and retrieve the individual strings and append to the sbOutputString. As the output string is changing as we loop thru the array it is good to use StringBuilder rather than System.String. Strings of type System.Text.StringBuilder are mutable where as strings of type System.String are immutable. If a string is manipulated many times always use StringBuilder over System.String.

6. Two good things to remember from this example are, follow the coding standards in naming the variables and always use StringBuilder class over Strings where we manipulate a particular string many times.

Question 2:
The XML file below has a list of employees. Your job is to bind the employee IDs and Names to a dropdownlist. ID must be dropdownlist value field and name must be the dropdownlist Text field. Also, only the active employees must be binded to the dropdownlist and the names should be in the ascending order. When I select a name from the dropdownlist, the name and ID of the selected employee must be printed on the webform.






Code sample:
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
DataSet DS = new DataSet();

DataView DV = DS.Tables["Employee"].DefaultView;
DV.RowFilter = "IsActive='true'";
DV.Sort = "Name asc";

DropDownList1.DataSource = DV;
DropDownList1.DataValueField = "ID";
DropDownList1.DataTextField = "Name";
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
Response.Write("Name Is : " + DropDownList1.SelectedItem.Text + " and ID is " + DropDownList1.SelectedItem.Value);

Code Explanation:
Read the XML data from Employees.xml file into a DataSet. We make use of the ReadXml() method. ReadXml method loads the XML data into the dataset DS. DS.ReadXml(Server.MapPath("Employees.xml"));

2. Now you have the Data in a relational format in the dataset. Create a DataView on the employees table in the DataSet. The DefaultView property of DataTable returns the DataView.
DataView DV = DS.Tables["Employee"].DefaultView;

3. After you have created the DataView, apply the RowFilter, to select only the active employees. You apply the RowFilter as shown below.
DV.RowFilter = "IsActive='true'";

4. Now sort the data in the DataView in ascending order. We sort the data on the Name column. You can apply the sort expression on a dataview as shown below.
DV.Sort = "Name asc";

5. Finally set the DataSource, DataValueField and DataTextField properties of the dropdownlist and call the DataBind() method as shown in the below code.
DropDownList1.DataSource = DV;
DropDownList1.DataValueField = "ID";
DropDownList1.DataTextField = "Name";

Untill now we have seen how to bind an XML file to dropdownlist. We have also seen how to create a DataView on DataTable. DataView is used for sorting and filtering the data. Now we have to get the SelecteValue and SelectedItem Text of a dropdownlist. To achieve this, follow the below steps.

1. Set the autopostback property of the dropdownlist to true. So, when ever a selection in the dropdownlist changes, the webform is posted back to the server automatically.

2. In the DropDownList1_SelectedIndexChanged event handler we can capture the employee name and id using the DropDownList1.SelectedItem.Text and DropDownList1.SelectedItem.Value properties as shown below.

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
Response.Write("Name Is : " + DropDownList1.SelectedItem.Text + " and ID is " + DropDownList1.SelectedItem.Value);

Note: If you have noticed, we binded the XML file to the dropdownlist only during the initial page load and not during every post back. We do this check by using if(!IsPostBack) property of the page.

201 killer cover letters

On disk are over 200 cover letters which can be customized to the user's specifications. As with a clip art library, this can be accessed and tailored to individual ends, including cover letters for every occasion from follow-ups and thank-yous to ad responses and job search inquiries. An excellent resource backed by a book format. -- Midwest Book Review --This text refers to an out of print or unavailable edition of this title. 

Product Description

201 Killer Cover Letters provides job seekers with an unbeatable competitive edge by arming them with surefire sample letters for every job-hunting situation. This edition of the bestselling guide includes the latest job-search techniques, tips for transferring job skills across industries, and ways to use the cover letter to anticipate and overcome "objectionable items or gaps in employment." Building on the success of the computer disk edition, the CD-ROM edition contains ready-to-download templates of all 201 letters, for CD-ROM-compatible computers, making it easier than ever for readers to tailor cover letters to specific situations.

Better job search in 3 easy steps

SQL Server Job Interview Questions part 5

Que:- What are the properties of the Relational tables? 
Ans:- Relational tables have six properties: 
• Values are atomic. 
• Column values are of the same kind. 
• Each row is unique. 
• The sequence of columns is insignificant. 
• The sequence of rows is insignificant. 
• Each column must have a unique name. 

Que:- What is De-normalization? 
Ans:- De-normalization is the process of attempting to optimize the performance of a database by adding redundant data. It is sometimes necessary because current DBMSs implement the relational model poorly. A true relational DBMS would allow for a fully normalized database at the logical level, while providing physical storage of data that is tuned for high performance. De-normalization is a technique to move from higher to lower normal forms of database modeling in order to speed up database access. 

Que:- How to get @@error and @@rowcount at the same time? 
Ans:- If @@Rowcount is checked after Error checking statement then it will have 0 as the value of @@Recordcount as it would have been reset. 
And if @@Recordcount is checked before the error-checking statement then @@Error would get reset. 
To get @@error and @@rowcount at the same time do both in same statement and store them in local variable. SELECT @RC = @@ROWCOUNT, @ER = @@ERROR 

Que:- What is Identity? 
Ans:- Identity (or AutoNumber) is a column that automatically generates numeric values. A start and increment value can be set, but most DBA leave these at 1. A GUID column also generates numbers, the value of this cannot be controled. Identity/GUID columns do not need to be indexed. 

Que:- What is a Scheduled Jobs or What is a Scheduled Tasks? 
Ans:- Scheduled tasks let user automate processes that run on regular or predictable cycles. User can schedule administrative tasks, such as cube processing, to run during times of slow business activity. User can also determine the order in which tasks run by creating job steps within a SQL Server Agent job. E.g. Back up database, Update Stats of Tables. Job steps give user control over flow of execution. 
If one job fails, user can configure SQL Server Agent to continue to run the remaining tasks or to stop execution. 

Que:- What is a table called, if it does not have neither Cluster nor Non-cluster Index? What is it 
used for? 

Ans:- Unindexed table or Heap. Microsoft Press Books and Book On Line (BOL) refers it as Heap. 
A heap is a table that does not have a clustered index and, therefore, the pages are not linked by pointers. The IAM pages are the only structures that link the pages in a table together. 
Unindexed tables are good for fast storing of data. Many times it is better to drop all indexes from table and than do bulk of inserts and to restore those indexes after that. 

Que:- What is BCP? When does it used? 
Ans:- BulkCopy is a tool used to copy huge amount of data from tables and views. BCP does not copy the structures same as source to destination. 

Que:- How do you load large data to the SQL server database? 
Ans:- BulkCopy is a tool used to copy huge amount of data from tables. BULK INSERT command helps to Imports a data file into a database table or view in a user-specified format. 

Que:- Can we rewrite subqueries into simple select statements or with joins? 
Ans:- Subqueries can often be re-written to use a standard outer join, resulting in faster performance. As we may know, an outer join uses the plus sign (+) operator to tell the database to return all non-matching rows with NULL values. Hence we combine the outer join with a NULL test in the WHERE clause to reproduce the result set without using a sub-query. 

Que:- Can SQL Servers linked to other servers like Oracle? 
Ans:- SQL Server can be lined to any server provided it has OLE-DB provider from Microsoft to allow a link. 
E.g. Oracle has a OLE-DB provider for oracle that Microsoft provides to add it as linked server to SQL Server group. 

Que:- How to know which index a table is using? 
Ans:- SELECT table_name,index_name FROM user_constraints 

Que:- How to copy the tables, schema and views from one SQL server to another? 
Ans:- Microsoft SQL Server 2000 Data Transformation Services (DTS) is a set of graphical tools and programmable objects that lets user extract, transform, and consolidate data from disparate sources into single or multiple destinations. 

Que:- What is Self Join? 
Ans:- This is a particular case when one table joins to itself, with one or two aliases to avoid confusion. A self join can be of any type, as long as the joined tables are the same. A self join is rather unique in that it involves a relationship with only one table. The common example is when company have a hierarchal reporting structure whereby one member of staff reports to another. 

Que:- What is Cross Join? 
Ans:- A cross join that does not have a WHERE clause produces the Cartesian product of the tables involved in the join. The size of a Cartesian product result set is the number of rows in the first table multiplied by the number of rows in the second table. The common example is when company wants to combine each product with a pricing table to analyze each product at each price. 

Que:- Which virtual table does a trigger use? 
Ans:- Inserted and Deleted. 

List few advantages of Stored Procedure. 
• Stored procedure can reduced network traffic and latency, boosting application performance. 
• Stored procedure execution plans can be reused, staying cached in SQL Server's memory, reducing server overhead. 
• Stored procedures help promote code reuse. 
• Stored procedures can encapsulate logic. You can change stored procedure code without 
affecting clients. 
• Stored procedures provide better security to your data. 

Que:- What is DataWarehousing? 
• Subject-oriented, meaning that the data in the database is organized so that all the data elements relating to the same real-world event or object are linked together; 
• Time-variant, meaning that the changes to the data in the database are tracked and recorded 
so that reports can be produced showing changes over time; 
• Non-volatile, meaning that data in the database is never over-written or deleted, once committed, the data is static, read-only, but retained for future reporting; 
• Integrated, meaning that the database contains data from most or all of an organization's operational applications, and that this data is made consistent. 

Que:- What is OLTP(OnLine Transaction Processing)? 
Ans:- In OLTP - online transaction processing systems relational database design use the discipline of data modeling and generally follow the Codd rules of data normalization in order to ensure absolute data integrity. Using these rules complex information is broken down into its most simple structures (a table) where all of the individual atomic level elements relate to each other and satisfy the normalization 

Que:- How do SQL server 2000 and XML linked? Can XML be used to access data? 
You can execute SQL queries against existing relational databases to return results as XML rather than standard rowsets. These queries can be executed directly or from within stored procedures. To retrieve XML results, use the FOR XML clause of the SELECT statement and specify an XML mode of RAW, AUTO, or EXPLICIT. 

OPENXML is a Transact-SQL keyword that provides a relational/rowset view over an in-memory XML document. OPENXML is a rowset provider similar to a table or a view. OPENXML provides a way to access XML data within the Transact-SQL context by transferring data from an XML document into the relational tables. Thus, OPENXML allows you to manage an XML document and its interaction with the relational environment. 

Que:- What is an execution plan? When would you use it? How would you view the execution plan? 
Ans:- An execution plan is basically a road map that graphically or textually shows the data retrieval methods chosen by the SQL Server query optimizer for a stored procedure or ad-hoc query and is a very useful tool for a developer to understand the performance characteristics of a query or stored procedure since the plan is the one that SQL Server will place in its cache and use to execute the stored procedure or 
query. From within Query Analyzer is an option called "Show Execution Plan" (located on the Query drop-down menu). If this option is turned on it will display query execution plan in separate window when query is ran again.

SQL Server Job Interview questions part 5

Que:- What are the different types of replication? Explain. 
Ans:- The SQL Server 2000-supported replication types are as follows: 
• Transactional 
• Snapshot 
• Merge 
Snapshot replication distributes data exactly as it appears at a specific moment in time and does not monitor for updates to the data. Snapshot replication is best used as a method for replicating data that changes infrequently or where the most up-to-date values (low latency) are not a requirement. When synchronization occurs, the entire snapshot is generated and sent to Subscribers. 

Transactional replication, an initial snapshot of data is applied at Subscribers, and then when data modifications are made at the Publisher, the individual transactions are captured and propagated to Subscribers. 

Merge replication is the process of distributing data from Publisher to Subscribers, allowing the Publisher and Subscribers to make updates while connected or disconnected, and then merging the updates between sites when they are connected. 

Que:- What are the OS services that the SQL Server installation adds? 
Ans:- MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transacco-ordinator) 

Que:- What are three SQL keywords used to change or set someone’s permissions? 

Que:- What does it mean to have quoted_identifier on? What are the implications of having it off? 
Ans:- When SET QUOTED_IDENTIFIER is ON, identifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks. When SET QUOTED_IDENTIFIER is OFF, identifiers cannot be quoted and must follow all Transact-SQL rules for identifiers. 

Que:- What is the STUFF function and how does it differ from the REPLACE function? 
Ans:- STUFF function to overwrite existing characters. Using this syntax, STUFF(string_expression, start, length, replacement_characters), string_expression is the string that will have characters substituted, start is the starting position, length is the number of characters in the string that are substituted, and 
replacement_characters are the new characters interjected into the string. 
REPLACE function to replace existing characters of all occurance. Using this syntax 
REPLACE(string_expression, search_string, replacement_string), where every incidence of search_string found in the string_expression will be replaced with replacement_string. 

Que:- Using query analyzer, name 3 ways to get an accurate count of the number of records in a 

Ans:- SELECT * FROM table1 
SELECT rows FROM sysindexes WHERE id = OBJECT_ID(table1) AND indid < 2 

Que:- How to rebuild Master Database? 
Ans:- Shutdown Microsoft SQL Server 2000, and then run Rebuildm.exe. This is located in the Program Files\Microsoft SQL Server\80\Tools\Binn directory. In the Rebuild Master dialog box, click Browse. In the Browse for Folder dialog box, select the \Data folder on the SQL Server 2000 compact disc or in the shared network directory from which SQL Server 2000 was installed, and then click OK. Click Settings. In the Collation Settings dialog box, verify or change settings used for the master database and all other databases. Initially, the default collation settings are shown, but these may not match the collation selected during setup. You can select the same settings used during setup or select new collation settings. When done, click OK. 
In the Rebuild Master dialog box, click Rebuild to start the process. The Rebuild Master utility reinstalls the master database. To continue, you may need to stop a server that is running. 

Que:- What is the basic functions for master, msdb, model, tempdb databases? 
Ans:- The Master database holds information for all databases located on the SQL Server instance and is the glue that holds the engine together. Because SQL Server cannot start without a functioning master database, you must administer this database with care. The msdb database stores information regarding database backups, SQL Agent information, DTS packages, SQL Server jobs, and some replication information such as for log shipping. 
The tempdb holds temporary objects such as global and local temporary tables and stored procedures. 
The model is essentially a template database used in the creation of any new user database created in the instance. 

Que:- What are primary keys and foreign keys? 
Ans:- Primary keys are the unique identifiers for each row. They must contain unique values and cannot be null. Due to their importance in relational databases, Primary keys are the most fundamental of all keys and constraints. A table can have only one Primary key. 
Foreign keys are both a method of ensuring data integrity and a manifestation of the relationship between tables. 

Que:- What is data integrity? Explain constraints? 
Ans:- Data integrity is an important feature in SQL Server. When used properly, it ensures that data is accurate, correct, and valid. It also acts as a trap for otherwise undetectable bugs within applications. A PRIMARY KEY constraint is a unique identifier for a row within a database table. Every table should have a primary key constraint to uniquely identify each row and only one primary key constraint can be 
created for each table. The primary key constraints are used to enforce entity integrity. 
A UNIQUE constraint enforces the uniqueness of the values in a set of columns, so no duplicate values are entered. The unique key constraints are used to enforce entity integrity as the primary key constraints. 
A FOREIGN KEY constraint prevents any actions that would destroy links between tables with the corresponding data values. A foreign key in one table points to a primary key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no primary keys with that value. The foreign key constraints are used to enforce referential integrity. A CHECK constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity. 
A NOT NULL constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints. 

SQL Server Job Interview Questions part 4

Que:- What is User Defined Functions? 
Ans:- User-Defined Functions allow to define its own T-SQL functions that can accept 0 or more parameters and return a single scalar data value or a table data type. 

Que:- What kind of User-Defined Functions can be created? 
Ans:- There are three types of User-Defined functions in SQL Server 2000 and they are Scalar, Inline Table-Valued and Multi-statement Table-valued. 

Scalar User-Defined Function 
A Scalar user-defined function returns one of the scalar data types. Text, ntext, image and timestamp data types are not supported. These are the type of user-defined functions that most developers are used to in other programming languages. You pass in 0 to many parameters and you get a return value. 

Inline Table-Value User-Defined Function 
An Inline Table-Value user-defined function returns a table data type and is an exceptional alternative to a view as the user-defined function can pass parameters into a T-SQL select command and in essence provide us with a parameterized, non-updateable view of the underlying tables. 

Multi-statement Table-Value User-Defined Function 
A Multi-Statement Table-Value user-defined function returns a table and is also an exceptional alternative to a view as the function can support multiple T-SQL statements to build the final result where the view is limited to a single SELECT statement. Also, the ability to pass parameters into a T-SQL select command or a group of them gives us the capability to in essence create a parameterized, 
non-updateable view of the data in the underlying tables. Within the create function command you must define the table structure that is being returned. After creating this type of user-defined function, It can be used in the FROM clause of a T-SQL command unlike the behavior found when using a stored procedure which can also return record sets. 

Que:- Which TCP/IP port does SQL Server run on? How can it be changed? 
Ans:- SQL Server runs on port 1433. It can be changed from the Network Utility TCP/IP properties –> Port number.both on client and the server. 

Que:- What are the authentication modes in SQL Server? How can it be changed? 
Ans:- Windows mode and mixed mode (SQL & Windows). 

To change authentication mode in SQL Server click Start, Programs, Microsoft SQL Server and click SQL Enterprise Manager to run SQL Enterprise Manager from the Microsoft SQL Server program group. 
Select the server then from the Tools menu select SQL Server Configuration Properties, and choose the Security page. 

Que:- Where are SQL server users names and passwords are stored in sql server? 
Ans:- They get stored in master db in the sysxlogins table. 

Que:- Which command using Query Analyzer will give you the version of SQL server and operating system? 
Ans:- SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition') 

Que:- What is SQL server agent? 
Ans:- SQL Server agent plays an important role in the day-to-day tasks of a database administrator (DBA). It is often overlooked as one of the main tools for SQL Server management. Its purpose is to ease the implementation of tasks for the DBA, with its full-function scheduling engine, which allows you to schedule your own jobs and scripts.

Que:- Can a stored procedure call itself or recursive stored procedure? How many level SP nesting possible? 
Ans:- Yes. Because Transact-SQL supports recursion, you can write stored procedures that call themselves. Recursion can be defined as a method of problem solving wherein the solution is arrived at by repetitively applying it to subsets of the problem. A common application of recursive logic is to perform numeric computations that lend themselves to repetitive evaluation by the same processing steps. 
Stored procedures are nested when one stored procedure calls another or executes managed code by referencing a CLR routine, type, or aggregate. You can nest stored procedures and managed code references up to 32 levels. 

Que:- What is @@ERROR? 
Ans:- The @@ERROR automatic variable returns the error code of the last Transact-SQL statement. If there was no error, @@ERROR returns zero. Because @@ERROR is reset after each Transact-SQL statement, it must be saved to a variable if it is needed to process it further after checking it. 

Que:- What is Raiseerror? 
Ans:- Stored procedures report errors to client applications via the RAISERROR command. RAISERROR doesn't change the flow of a procedure; it merely displays an error message, sets the @@ERROR automatic variable, and optionally writes the message to the SQL Server error log and the NT application event log. 

Que:- What is log shipping? 
Ans:- Log shipping is the process of automating the backup of database and transaction log files on a production SQL server, and then restoring them onto a standby server. Enterprise Editions only supports log shipping. In log shipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db can be used this as the Disaster Recovery plan. The key feature of log shipping is that is will automatically backup transaction logs throughout the day and automatically restore them on the standby server at defined interval. 

Que:- What is the difference between a local and a global variable? 
Ans:- A local temporary table exists only for the duration of a connection or, if defined inside a compound statement, for the duration of the compound statement. 

A global temporary table remains in the database permanently, but the rows exist only within a given connection. When connection are closed, the data in the global temporary table disappears. However, the table definition remains with the database for access when database is opened next time. 

Que:- What command do we use to rename a db? 
Ans:- sp_renamedb ‘oldname’ , ‘newname’ If someone is using db it will not accept sp_renmaedb. In that case first bring db to single user using sp_dboptions. Use sp_renamedb to rename database. Use sp_dboptions to bring database to multi user 

Que:- What is sp_configure commands and set commands? 
Ans:- Use sp_configure to display or change server-level settings. To change database-level settings, use ALTER DATABASE. To change settings that affect only the current user session, use the SET statement. 

SQL Server Job Interview questions part 3

Que:- What is a NOLOCK? 
Ans:- Using the NOLOCK query optimiser hint is generally considered good practice in order to improve concurrency on a busy system. When the NOLOCK hint is included in a SELECT statement, no locks are taken when data is read. The result is a Dirty Read, which means that another process could be updating the data at the exact time you are reading it. There are no guarantees that your query will retrieve the most recent data. The advantage to performance is that your reading of data will not block 
updates from taking place, and updates will not block your reading of data. SELECT statements take Shared (Read) locks. This means that multiple SELECT statements are allowed simultaneous access, but other processes are blocked from modifying the data. The updates will queue until all the reads have completed, and reads requested after the update will wait for the updates to complete. The result to your system is delay(blocking). 

Que:- What is difference between DELETE & TRUNCATE commands? 
Ans:- Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command. 

TRUNCATE is faster and uses fewer system and transaction log resources than DELETE. 
TRUNCATE removes the data by deallocating the data pages used to store the table’s data, and only the 
page deallocations are recorded in the transaction log. 
TRUNCATE removes all rows from a table, but the table structure and its columns, constraints, indexes and so on remain. The counter used by an identity for new rows is reset to the seed for the column. 
You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint.
Because TRUNCATE TABLE is not logged, it cannot activate a trigger. 
TRUNCATE can not be Rolled back. 
TRUNCATE is DDL Command. 
TRUNCATE Resets identity of the table. 

DELETE removes rows one at a time and records an entry in the transaction log for each deleted row. 
If you want to retain the identity counter, use DELETE instead. If you want to remove table definition 
and its data, use the DROP TABLE statement. 
DELETE Can be used with or without a WHERE clause 
DELETE Activates Triggers. 
DELETE Can be Rolled back. 
DELETE is DML Command. 
DELETE does not reset identity of the table. 

Que:- Difference between Function and Stored Procedure? 
Ans:- UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as Stored procedures cannot be. 
UDFs that return tables can be treated as another rowset. This can be used in JOINs with other tables. 
Inline UDF's can be though of as views that take parameters and can be used in JOINs and other Rowset operations. 

Que:- When is the use of UPDATE_STATISTICS command? 
Ans:- This command is basically used when a large processing of data has occurred. If a large amount of deletions any modification or Bulk Copy into the tables has occurred, it has to update the indexes to take these changes into account. UPDATE_STATISTICS updates the indexes on these tables accordingly. 

Que:- What types of Joins are possible with Sql Server? 
Ans:- Joins are used in queries to explain how different tables are related. Joins also let you select data from a table depending upon data from another table. 

Que:- What is the difference between a HAVING CLAUSE and a WHERE CLAUSE? 
Ans:- Specifies a search condition for a group or an aggregate. 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. 

Que:- What is sub-query? Explain properties of sub-query. 
Ans:- Sub-queries are often referred to as sub-selects, as they allow a SELECT statement to be executed arbitrarily within the body of another SQL statement. A sub-query is executed by enclosing it in a set of parentheses. Sub-queries are generally used to return a single row as an atomic value, though they may be used to compare values against multiple rows with the IN keyword. 
A subquery is a SELECT statement that is nested within another T-SQL statement. A subquery SELECT statement if executed independently of the T-SQL statement, in which it is nested, will return a result set. Meaning a subquery SELECT statement can standalone and is not depended on the statement in which it is nested. A subquery SELECT statement can return any number of values, and can be found in, the column list of a SELECT statement, a FROM, GROUP BY, HAVING, and/or ORDER BY clauses of a T-SQL statement.
A Subquery can also be used as a parameter to a function call. Basically a subquery can be used anywhere an expression can be used. 

Properties of Sub-Query 
A subquery must be enclosed in the parenthesis. 
A subquery must be put in the right hand of the comparison operator, and 
A subquery cannot contain a ORDER-BY clause. 
A query can contain more than one sub-queries. 

Que:- What are types of sub-queries? 
Ans:- Single-row subquery, where the subquery returns only one row. 
Multiple-row subquery, where the subquery returns multiple rows,.and 
Multiple column subquery, where the subquery returns multiple columns. 

Que:- What is SQL Profiler? 
Ans:- SQL Profiler is a graphical tool that allows system administrators to monitor events in an instance of Microsoft SQL Server. You can capture and save data about each event to a file or SQL Server table to analyze later. For example, you can monitor a production environment to see which stored procedures 
are hampering performance by executing too slowly. 
Use SQL Profiler to monitor only the events in which you are interested. If traces are becoming too large, you can filter them based on the information you want, so that only a subset of the event data is collected. Monitoring too many events adds overhead to the server and the monitoring process and can cause the trace file or trace table to grow very large, especially when the monitoring process takes 
place over a long period of time. 

SQL Server Job Interview questions part 2

Que:- What is Index? 
Ans:- An index is a physical structure containing pointers to the data. Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes, they are just used to speed 
up queries. Effective indexes are one of the best ways to improve performance in a database application. A table scan happens when there is no index available to help a query. In a table scan SQL Server examines every row in the table to satisfy the query results. Table scans are sometimes unavoidable, but on large tables, scans have a terrific impact on performance. 

Clustered indexes define the physical sorting of a database table’s rows in the storage media. For this reason, each database table may have only one clustered index. Non-clustered indexes are created outside of the database table and contain a sorted list of references to the table itself. 

Que:- What is the difference between clustered and a non-clustered index? 
Ans:- A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages. 

A nonclustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a nonclustered index does not consist of the data pages. Instead, the leaf nodes contain index rows. 

Que:- What are the different index configurations a table can have? 
Ans:- A table can have one of the following index configurations: 
No indexes 
A clustered index 
A clustered index and many nonclustered indexes 
A nonclustered index 
Many nonclustered indexes 

Que:- What is cursors? 
Ans:- 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. 

In order to work with a cursor we need to perform some steps in the following order: 
Declare cursor
Open cursor
Fetch row from the cursor
Process fetched row Close cursor
Deallocate cursor 

Que:- What is the use of DBCC commands? 
Ans:- DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks. 
E.g. DBCC CHECKDB - Ensures that tables in the db and the indexes are correctly linked. 
DBCC CHECKALLOC - To check that all pages in a db are correctly allocated. 
DBCC CHECKFILEGROUP - Checks all tables file group for any damage. 

Que:- What is a Linked Server? 
Ans:- Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements. With a linked server, you can create very clean, easy to follow, SQL statements that allow remote data to be retrieved, joined and combined with local data. 
Storped Procedure sp_addlinkedserver, sp_addlinkedsrvlogin will be used add new Linked Server. 

Que:- What is Collation? 
Ans:- Collation refers to a set of rules that determine how data is sorted and compared. Character data is sorted using rules that define the correct character sequence, with options for specifying case-sensitivity, accent marks, kana character types and character width. 

Que:- What are different type of Collation Sensitivity? 
Ans:- Case sensitivity 
A and a, B and b, etc. 

Accent sensitivity 
a and á, o and ó, etc. 

Kana Sensitivity 
When Japanese kana characters Hiragana and Katakana are treated differently, it is called Kana sensitive. 

Width sensitivity 
When a single-byte character (half-width) and the same character when represented as a double-byte character (full-width) are treated differently then it is width sensitive. 

Que:- What's the difference between a primary key and a unique key? 
Ans:- Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only. 

Que:- How to implement one-to-one, one-to-many and many-to-many relationships while designing tables? 
Ans:- One-to-One relationship can be implemented as a single table and rarely as two tables with primary and foreign key relationships. One-to-Many relationships are implemented by splitting the data into two tables with primary key and foreign key relationships. Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table. 

SQL Server Interview questions - part 1

Que:- What is RDBMS? 
Ans:- Relational Data Base Management Systems (RDBMS) are database management systems that maintain data records and indices in tables. Relationships may be created and maintained across and among the data and tables. In a relational database, relationships between data items are expressed by means of tables. Interdependencies among these tables are expressed by data values rather than by pointers. 
This allows a high degree of data independence. An RDBMS has the capability to recombine the data items from different files, providing powerful tools for data usage. 

Que:- What is normalization? 
ANs:- Database normalization is a data design and organization process applied to data structures based on rules that help build relational databases. In relational database design, the process of organizing data to minimize redundancy. Normalization usually involves dividing a database into two or more tables and defining relationships between the tables. The objective is to isolate data so that additions, deletions, and modifications of a field can be made in just one table and then propagated through the rest of the database via the defined relationships. 

Que:- What are different normalization forms? 
1NF: Eliminate Repeating Groups Make a separate table for each set of related attributes, and give each table a primary key. Each field contains at most one value from its attribute domain. 
2NF: Eliminate Redundant Data 
If an attribute depends on only part of a multi-valued key, remove it to a separate table. 
3NF: Eliminate Columns Not Dependent On Key 
If attributes do not contribute to a description of the key, remove them to a separate table. All attributes must be directly dependent on the primary key 
BCNF: Boyce-Codd Normal Form If there are non-trivial dependencies between candidate key attributes, separate them out into distinct tables. 
4NF: Isolate Independent Multiple Relationships 
No table may contain two or more 1:n or n:m relationships that are not directly related. 
5NF: Isolate Semantically Related Multiple Relationships 
There may be practical constrains on information that justify separating logically related many-to-many relationships. 
ONF: Optimal Normal Form A model limited to only simple (elemental) facts, as expressed in Object Role Model notation. 
DKNF: Domain-Key Normal Form 
A model free from all modification anomalies. 

Remember, these normalization guidelines are cumulative. For a database to be in 3NF, it must first fulfill all the criteria of a 2NF and 1NF database. 

Que:- What is Stored Procedure? 
Ans:-A stored procedure is a named group of SQL statements that have been previously created and stored in the server database. Stored procedures accept input parameters so that a single procedure can be used over the network by several clients using different input data. And when the procedure is modified, all clients automatically get the new version. Stored procedures reduce network traffic and improve performance. Stored procedures can be used to help ensure the integrity of the database. 
e.g. sp_helpdb, sp_renamedb, sp_depends etc. 

Que:- What is Trigger? 
Ans:-A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or UPDATE) occurs. Triggers are stored in and managed by the DBMS.Triggers are used to maintain the referential integrity of data by changing the data in a systematic fashion. A trigger cannot be called or executed; the DBMS automatically fires the trigger as a result of a data modification to the associated table. 
Triggers can be viewed as similar to stored procedures in that both consist of procedural logic that is stored at the database level. Stored procedures, however, are not event-drive and are not attached to a specific table as triggers are. Stored procedures are explicitly executed by invoking a CALL to the procedure while triggers are implicitly executed. In addition, triggers can also execute stored procedures. 

Nested Trigger: A trigger can also contain INSERT, UPDATE and DELETE logic within itself, so when the trigger is fired because of data modification it can also cause another data modification, thereby firing another trigger. A trigger that contains data modification logic within itself is called a nested trigger. 

Que:- What is View? 
Ans:- A simple view can be thought of as a subset of a table. It can be used for retrieving data, as well as updating or deleting rows. Rows updated or deleted in the view are updated or deleted in the table the view was created with. It should also be noted that as data in the original table changes, so does data in the view, as views are the way to look at part of the original table. The results of using a view are 
not permanently stored in the database. The data accessed through a view is actually constructed using standard T-SQL select command and can come from one to many different base tables or even other views. 

asp .net : Remote and Web service Interview questions

Que:- What is .NET Remoting ?
Ans:- .NET remoting is replacement of DCOM. Using .NET remoting you can make remote
object calls which lie in different Application Domains. As the remote objects run in
different process client calling the remote object can not call it directly. So the client uses
a proxy which looks like a real object.

When client wants to make method call on the remote object it uses proxy for it. These
method calls are called as “Messages”. Messages are serialized using “formatter” class
and sent to client “channel”. Client Channel communicates with Server Channel. Server
Channel uses as formatter to deserialize the message and sends to the remote object.

Que:- Which class does the remote object has to inherit ?
Ans:- All remote objects should inherit from System.MarshalbyRefObject.

Que:- What are two different types of remote object creation mode in .NET ?
Ans:- There are two different ways in which object can be created using Remoting :-
SAO (Server Activated Objects) also called as Well-Known call mode.
CAO (Client Activated Objects)

SAO has two modes “Single Call” and “Singleton”. With Single Call object the object is
created with every method call thus making the object stateless. With Singleton the object
is created only once and the object is shared with all clients.

CAO are stateful as compared to SAO. In CAO the creation request is sent from client
side. Client holds a proxy to the server object created on server.

Que:- Describe in detail Basic of SAO architecture of Remoting?
Remoting has at least three sections :-
* Common Interface which will be shared between them.
* Server.
* Client.

Que:- What are the situations you will use singleton architecture in remoting ?
Ans:- If all remoting clients have to share the same data singleton architecture will be used.

Que:- What are the ways in which client can create object on server in CAO model ?
Ans:- There are two ways by which you can create Client objects on remoting server :
By Keyword “New”

Que:- How can we call methods in remoting Asynchronously ?
Ans:- All previous examples are a synchronous method calls that means client has to wait until
the method completes the process. By using Delegates we can make Asynchronous method

Que:- What is Asynchronous One-Way Calls ?
Ans:- One-way calls are a different from asynchronous calls from execution angle that the .NET
Framework does not guarantee their execution. In addition, the methods used in this kind
of call cannot have return values or out parameters. One-way calls are defined by using
[OneWay()] attribute in class.

Que:- What is marshalling and what are different kinds of marshalling ?
Ans:- Marshaling is used when an object is converted so that it can be sent across the network
or across application domains. Unmarshaling creates an object from the marshaled data.
There are two ways to do marshalling :-

Marshal-by-value (MBV) :- In this the object is serialized into the channel, and
a copy of the object is created on the other side of the network. The object to
marshal is stored into a stream, and the stream is used to build a copy of the
object on the other side with the unmarshalling sequence.

Marshaling-by-reference (MBR):- Here it creates a proxy on the client that is
used to communicate with the remote object. The marshaling sequence of a
remote object creates an ObjRef instance that itself can be serialized across
the network.

Que:- What is ObjRef object in remoting ?
Ans:- All Marshal() methods return ObjRef object.The ObjRef is serializable because it
implements the interface ISerializable, and can be marshaled by value. The ObjRef knows
about :-
* location of the remote object
* host name
* port number
* object name


Que:- What is a Web Service ?
Ans:- Web Services are business logic components which provide functionality via the Internet
using standard protocols such as HTTP.
Web Services uses Simple Object Access Protocol (SOAP) in order to expose the business
functionality.SOAP defines a standardized format in XML which can be exchanged
between two entities over standard protocols such as HTTP. SOAP is platform independent
so the consumer of a Web Service is therefore completely shielded from any
implementation details about the platform exposing the Web Service. For the consumer it
is simply a black box of send and receive XML over HTTP. So any web service hosted on
windows can also be consumed by UNIX and LINUX platform.

Que:- What is UDDI ?
Ans:- Full form of UDDI is Universal Description, Discovery and Integration. It is a directory
that can be used to publish and discover public Web Services. If you want to see more
details you can visit the .

Que:- What is DISCO ?
Ans:- DISCO is the abbreviated form of Discovery. It is basically used to club or group common
services together on a server and provides links to the schema documents of the services
it describes may require.

Que:- What is WSDL?
Ans:- Web Service Description Language (WSDL)is a W3C specification which defines XML
grammar for describing Web Services.XML grammar describes details such as:-
* Where we can find the Web Service (its URI)?
* What are the methods and properties that service supports?
* Data type support.
* Supported protocols

In short its a bible of what the webservice can do.Clients can consume this WSDL and
build proxy objects that clients use to communicate with the Web Services. Full WSDL
specification is available at

Que:- What is file extension of Webservices ?
Ans:- .ASMX is extension for Webservices.

Que:-Which attribute is used in order that the method can be used as WebService?
Ans:- WebMethod attribute has to be specified in order that the method and property can be
treated as WebService.

Que:- Do webservice have state ?
Twist :- How can we maintain State in Webservices ?

Webservices as such do not have any mechanism by which they can maintain state.
Webservices can access ASP.NET intrinsic objects like Session, application and so on if
they inherit from “WebService” base class.

Imports System.Web.Services
Public class TestWebServiceClass
Inherits WebService
Public Sub SetSession(value As String)
session("Val") = Value
End Sub
end class

Above is a sample code which sets as session object called as “val”. TestWebserviceClass
is inheriting from WebService to access the session and application objects.

Secret Interview questions related to asp .net framework

Que:- What is a IL?
Ans:-(IL)Intermediate Language is also known as MSIL (Microsoft Intermediate Language)(Common Intermediate Language). All .NET source code is compiled to IL. This IL is converted to machine code at the point where the software is installed, or at run-time by a Just In Time (JIT) compiler.

Que:- What is a CLR?
Ans: Full form of CLR is Common Language Runtime and it forms the heart of the .NET frame All Languages have runtime and its the responsibility of the runtime to take care of the execution of the program. For example VC++ has MSCRT40.DLL,VB6 has MSVBVM60.Java has Java Virtual Machine etc. Similarly .NET has CLR. Following are the responsibility CLR 

Garbage Collection :- CLR automatically manages memory thus eliminating memory leaks. When objects are not referred GC automatically releases those
memories thus providing efficient memory management.

Code Access Security :- CAS grants rights to program depending on the securi
configuration of the machine. Example the program has rights to edit or creat
a new file but the security configuration of machine does not allow the progra
to delete a file. CAS will take care that the code runs under the environment o
machines security configuration.

Code Verification :- This ensures proper code execution and type safety while
the code runs. It prevents the source code to perform illegal operation such as
accessing invalid memory locations etc.

IL( Intermediate language )-to-native translators and optimizer’s :- CLR uses
JIT and compiles the IL code to machine code and then executes. CLR also
determines depending on platform what is optimized way of running the IL code.

Oue:- What is a CLS(Common Language Specification)?
Ans:- This is a subset of the CTS which all .NET languages are expected to support. It was always a dream of Microsoft to unite all different languages in to one umbrella and CLS is one step towards that. Microsoft has defined CLS which are nothing but guidelines that language to follow so that it can communicate with other .NET languages in a seamless manner.

Que:- What is a Managed Code?
Ans:- Managed code runs inside the environment of CLR i.e. .NET runtime. In short all IL are managed code. But if you are using some third party software example VB6 or VC++ component they are unmanaged code as .NET runtime (CLR) does not have control over the source code execution of the language.

Que:- What is a Assembly?
Ans:- 1)Assembly is unit of deployment like EXE or a DLL.
2)An assembly consists of one or more files (dlls, exe’s, html files etc.), and
represents a group of resources, type definitions, and implementations of those
types. An assembly may also contain references to other assemblies. These
resources, types and references are described in a block of data called a manifest.
The manifest is part of the assembly, thus making the assembly self-describing.
3)An assembly is completely self-describing.An assembly contains metadata
information, which is used by the CLR for everything from type checking and
security to actually invoking the components methods. As all information is in the
assembly itself, it is independent of registry. This is the basic advantage as
compared to COM where the version was stored in registry.

Que:- What are the different types of Assembly?
Ans:- There are two types of assembly Private and Public assembly. A private assembly is normally used by a single application, and is stored in the application's directory, or a sub-directory beneath. A shared assembly is normally stored in the global assembly cache, which is a repository of assemblies maintained by the .NET runtime. Shared assemblies are usually libraries of code which many applications will find useful, e.g. Crystal report classes which will be used by all application for

Que:- What is NameSpace?
Ans:- Namespace has two basic functionality :-

NameSpace Logically group types, example System.Web.UI logically groups
our UI related features.

In Object Oriented world many times its possible that programmers will use the
same class name.By qualifying NameSpace with classname this collision is able to
be removed.

Que: What is Difference between NameSpace and Assembly?
Ans:- Following are the differences between namespace and assembly :

Assembly is physical grouping of logical units. Namespace logically groups

Namespace can span multiple assembly.

Que:- What is garbage collection?
Ans:- Garbage collection is a CLR feature which automatically manages memory. Programmers forget to release the objects while coding ..... Laziness (Remember in VB6 where one of the good practices is to set object to nothing). CLR automatically releases objects when they are no longer in use and refernced. CLR runs on non-deterministic to see the unused objects and cleans them. One side effect of this non-deterministic feature is that we cannot assume an object is destroyed when
it goes out of the scope of a function. Therefore, we should not put code into a class destructor to release resources.

Que:- What is reflection?
Ans:- All .NET assemblies have metadata information stored about the types defined in modules. This metadata information can be accessed by mechanism called as “Reflection”.System. Reflection can be used to browse through the metadata information. Using reflection you can also dynamically invoke methods using System.Type.Invokemember. Below is sample source code.

Public Class Form1 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim Pobjtype As Type
Dim PobjObject As Object
Dim PobjButtons As New Windows.Forms.Button()
Pobjtype = PobjButtons.GetType()
For Each PobjObject In Pobjtype.GetMembers
End Sub
End Class

Que:- What are Value types and Reference types ?
Ans:- Value types directly contain their data which are either allocated on the stack or allocated in-line in a structure.
Reference types store a reference to the value's memory address, and are allocated on the heap.
Reference types can be self-describing types, pointer types, or interface types.
Variables that are value types each have their own copy of the data, and therefore operations on
one variable do not affect other variables. Variables that are reference types can refer to the same
object; therefore, operations on one variable can affect the same object referred to by another
variable. All types derive from the System.Object base type.

Most Important Question.

Que:- What is the difference between VB.NET and C# ?
Ans:- Well this is the most debatable issue in .NET community and people treat there languages like religion. Its a subjective matter which language is best. Some like VB.NET’s natural style and some like professional and terse C# syntaxes. Both use the same framework and speed is also very much equivalents. But still let’s list down 

some major differences between them :-

Advantages VB.NET :-

* Has support for optional parameters which makes COM interoperability much easy.
* With Option Strict off late binding is supported.Legacy VB functionalities can be
used by using Microsoft.VisualBasic namespace.
* Has the WITH construct which is not in C#.
* The VB.NET part of Visual Studio .NET compiles your code in the background.
While this is considered an advantage for small projects, people creating very 
large projects have found that the IDE slows down considerably as the project gets 

Advantages of C#

* XML documentation is generated from source code but this is now been incorporated
in Whidbey.
* Operator overloading which is not in current VB.NET but is been introduced in
* Use of this statement makes unmanaged resource disposal simple.
* Access to Unsafe code. This allows pointer arithmetic etc, and can improve
performance in some situations. However, it is not to be used lightly, as a lot of 
the normal safety of C# is lost (as the name implies).This is the major difference 
that you can access unmanaged code in C# and not in VB.NET.

Que:- What is the difference between System exceptions and Application exceptions?
Ans:- All exception derives from Exception Base class. Exceptions can be generated programmatically or can be generated by system. Application Exception serves as the base class for all application- specific exception classes. It derives from Exception but does not provide any extended functionality. You should derive your custom application exceptions from Application Exception. Application exception is used when we want to define user defined exception, while system exception is all which is defined by .NET.

Que:- What is the difference between Convert.toString and .toString()method ?
Ans:- Just to give an understanding of what the above question means seethe below code.

int i =0;

We can convert the integer “i” using “i.ToString()” or “Convert.ToString” so what’s the difference.
The basic difference between them is “Convert” function handles NULLS while “i.ToString()”
does not it will throw a NULL reference exception error. So as good coding practice using
“convert” is always safe.

ASP .NET Job Interview Questions

Que:- What is the sequence in which ASP.NET events are processed ?
Ans:- Following is the sequence in which the events occur :-
* Page_Init.
* Page_Load.
* Control events.
* Page_Unload event.
Page_init event only occurs when first time the page is started, but Page_Load occurs in subsequent request of the page.

Que:- In which event are the controls fully loaded ?
Ans:- Page_load event guarantees that all controls are fully loaded. Controls are also accessed in Page_Init events but you will see that viewstate is not fully loaded during this event.

Que:- How can we identify that the Page is PostBack ?
Ans:- Page object has a “IsPostBack” property which can be checked to know that is the page posted back.

Que:-What is event bubbling ?
Ans:- Server controls like Datagrid, DataList, Repeater can have other child controls inside them. Example DataGrid can have combo box inside datagrid. These child control do not raise there events by themselves, rather they pass the event to the container parent (which can be a datagrid, datalist, repeater), which passed to the page as “ItemCommand” event. As the child control send there events to parent this is termed as event bubbling.

Que:- If we want to make sure that no one has tampered with ViewState, how do we ensure it?
Ans:- Using the @Page directive EnableViewStateMac to True.

Que:- What is AppSetting Section in “Web.Config” file?
Ans:- Web.config file defines configuration for a webproject. Using “AppSetting” section we can define user defined values. Example below defined is ConnectionString” section which will be used through out the project for database connection.

Que:- Where is ViewState information stored ?
Ans:- In HTML Hidden Fields.

Que:- How can we create custom controls in ASP.NET ?
Ans:- User controls are created using .ASCX in ASP.NET. After .ASCX file is created you need to two things in order that the ASCX can be used in project:

* Register the ASCX control in page using the 
* Now to use the above accounting footer in page you can use the below directive.

Que:- How many types of validation controls are provided by ASP.NET ?
Ans:- There are six main types of validation controls :-
1). RequiredFieldValidator :-

It checks whether the control have any value. It's used when you want the control should not be empty.

2). RangeValidator :- 

It checks if the value in validated control is in that specific range. Example
TxtCustomerCode should not be more than eight length.

3). CompareValidator:-

It checks that the value in controls should match the value in other control. Example
Textbox TxtPie should be equal to 3.14.

4). RegularExpressionValidator:-

When we want the control value should match with a specific regular expression.

5). CustomValidator:-

It is used to define UserDefined validation.

6). ValidationSummary:-

It displays summary of all current validation errors.

Que:- Can you explain what is “AutoPostBack” feature in ASP.NET ?
Ans:- If we want the control to automatically postback in case of any event, we will need to check this attribute as true. Example on a ComboBox change we need to send the event immediately to the server side then set the “AutoPostBack” attribute to true.

Que:- How can you enable automatic paging in DataGrid ?
Ans:- Following are the points to be done in order to enable paging in Datagrid :-
* Set the “AllowPaging” to true.
* In PageIndexChanged event set the current pageindex clicked.

Que:-What is the difference between “Web.config” and “Machine.Config” ?
Ans:- “Web.config” files apply settings to each web application, while Machine.config” file apply settings to all ASP.NET applications.

Que:- What is the difference between Server.Transfer and response.Redirect ?
Ans:- Following are the major differences between them:-
* Response.Redirect sends message to the browser saying it to move to some
different page, while server.transfer does not send any message to the browser
but rather redirects the user directly from the server itself. So in server.transfer
there is no round trip while response.redirect has a round trip and hence puts
a load on server.

* Using Server.Transfer you can not redirect to a different from the server itself.
Example if your server is you can use server.transfer to move
to but yes you can move to, i.e.
within websites. This cross server redirect is possible only using

* With server.transfer you can preserve your information. It has a parameter
called as “preserveForm”. So the existing query string etc. will be able in the
calling page. In response.redirect you can maintain the state, but has
lot of drawbacks.

Que:- What is the difference between Authentication and authorization?
Ans:- This can be a tricky question. These two concepts seem altogether similar but there is wide range of difference. Authentication is verifying the identity of a user and authorization is process where we check does this identity have access rights to the system. In short we can say the following authentication is the process of obtaining some sort of credentials from the users and using those credentials to verify the user’s identity. Authorization is the process of allowing an authenticated user access to resources. Authentication always proceed to Authorization; even if your application lets anonymous users connect and use
the application, it still authenticates them as being anonymous.

Que:- What are the various ways of authentication techniques in ASP.NET?
Ans:- Selecting an authentication provider is as simple as making an entry in the web.config file for the application. You can use one of these entries to select the corresponding built in authentication provider:

* authentication mode=”windows”
* authentication mode=”passport”
* authentication mode=”forms”
* Custom authentication where you might install an ISAPI filter in IIS that
compares incoming requests to list of source IP addresses, and considers
requests to be authenticated if they come from an acceptable address. In that
case, you would set the authentication mode to none to prevent any of the
.net authentication providers from being triggered.

Que:- How does authorization work in ASP.NET?
Ans:- ASP.NET impersonation is controlled by entries in the applications web.config file. The default setting is “no impersonation”. You can explicitly specify that ASP.NET shouldn’t use impersonation by including the following code in the file

It means that ASP.NET will not perform any authentication and runs with its own
privileges. By default ASP.NET runs as an unprivileged account named ASPNET. You
can change this by making a setting in the processModel section of the machine.config
file. When you make this setting, it automatically applies to every site on the server. To user a high-privileged system account instead of a low-privileged set the userNameattribute of the processModel element to SYSTEM. Using this setting is a definite security risk, as it elevates the privileges of the ASP.NET process to a point where it can do bad things to the operating system.

Que:- What’s difference between Datagrid, Datalist and repeater ?
Ans:- A Datagrid, Datalist and Repeater are all ASP.NET data Web controls.
They have many things in common like DataSource Property, DataBind Method
ItemDataBound and ItemCreated.
When you assign the DataSource Property of a Datagrid to a DataSet then each DataRow
present in the DataRow Collection of DataTable is assigned to a corresponding
DataGridItem and this is same for the rest of the two controls also. But The HTML code generated for a Datagrid has an HTML TABLE element created for the particular DataRow and its a Table form representation with Columns and Rows.
For a Datalist its an Array of Rows and based on the Template Selected and the
RepeatColumn Property value We can specify how many DataSource records should
appear per HTML table row. In short in datagrid we have one record per row, but in
datalist we can have five or six rows per row.
For a Repeater Control, the Datarecords to be displayed depends upon the Templates
specified and the only HTML generated is the due to the Templates.
In addition to these, Datagrid has a in-built support for Sort, Filter and paging the Data,which is not possible when using a DataList and for a Repeater Control we would require to write an explicit code to do paging.

Que:- From performance point of view how do they rate ?
Ans:- Repeater is fastest followed by Datalist and finally datagrid.

Que:- What is the method to customize columns in DataGrid?
Ans:- Use the template column.

Que:- How can we format data inside DataGrid?
Ans:- Use the DataFormatString property.

Que:- How to decide on the design consideration to take a Datagrid, datalist or repeater ?
Ans:- Many make a blind choice of choosing datagrid directly, but that's not the right way.
Datagrid provides ability to allow the end-user to sort, page, and edit its data. But it comes at a cost of speed. Second the display format is simple that is in row and columns.
Real life scenarios can be more demanding that With its templates, the DataList provides more control over the look and feel of the displayed data than the DataGrid. It offers better performance than datagrid Repeater control allows for complete and total control. With the Repeater, the only HTML emitted are the values of the databinding statements in the templates along with the HTML markup specified in the templates—no "extra" HTML is emitted, as with the DataGrid and DataList. By requiring the developer to specify the complete generated HTML markup, the Repeater often requires the longest development time. But repeater does not provide editing features like datagrid so everything has to be coded by programmer. However, the Repeater does boast the best performance of the three data Web controls.
Repeater is fastest followed by Datalist and finally datagrid.

Que:- Difference between ASP and ASP.NET?
Ans:- ASP.NET new feature supports are as follows :-

Better Language Support

* New ADO.NET Concepts have been implemented.
ASP.NET supports full language (C#, VB.NET, C++) and not simple scripting

Better controls than ASP

* ASP.NET covers large set’s of HTML controls..
* Better Display grid like Datagrid, Repeater and datalist.Many of the display
grids have paging support.

Controls have events support

* All ASP.NET controls support events.
* Load, Click and Change events handled by code makes coding much simpler and much better organized.

Compiled Code

The first request for an ASP.NET page on the server will compile the ASP.NET code and
keep a cached copy in memory. The result of this is greatly increased performance.
Better Authentication Support
ASP.NET supports forms-based user authentication, including cookie management and
automatic redirecting of unauthorized logins. (You can still do your custom login page and custom user checking).

User Accounts and Roles

ASP.NET allows for user accounts and roles, to give each user (with a given role) access to different server code and executables.

High Scalability

* Much has been done with ASP.NET to provide greater scalability.
* Server to server communication has been greatly enhanced, making it possible
to scale an application over several servers. One example of this is the ability
to run XML parsers, XSL transformations and even resource hungry session objects on other servers.

Easy Configuration

Configuration of ASP.NET is done with plain text files.
* Configuration files can be uploaded or changed while the application is running.
No need to restart the server. No more metabase or registry puzzle.

Easy Deployment

No more server restart to deploy or replace compiled code. ASP.NET simply redirects all new requests to the new code.

Que:- What are major events in GLOBAL.ASAX file ?
Ans:- The Global.asax file, which is derived from the HttpApplication class, maintains a pool
of HttpApplication objects, and assigns them to applications as needed. The Global.asax
file contains the following events:

Application_Init: Fired when an application initializes or is first called. It is invoked for
all HttpApplication object instances.

Application_Disposed: Fired just before an application is destroyed. This is the ideal
location for cleaning up previously used resources.

Application_Error: Fired when an unhandled exception is encountered within the

Application_Start: Fired when the first instance of the HttpApplication class is created.
It allows you to create objects that are accessible by all HttpApplication instances.
Application_End: Fired when the last instance of an HttpApplication class is destroyed.
It is fired only once during an application's lifetime.

Application_BeginRequest: Fired when an application request is received. It is the first
event fired for a request, which is often a page request (URL) that a user enters.

Application_EndRequest: The last event fired for an application request.

Application_PreRequestHandlerExecute: Fired before the ASP.NET page framework
begins executing an event handler like a page or Web service.

Application_PostRequestHandlerExecute: Fired when the ASP.NET page framework has finished executing an event handler

Applcation_PreSendRequestHeaders: Fired before the ASP.NET page framework sends
HTTP headers to a requesting client (browser).

Application_UpdateRequestCache: Fired when the ASP.NET page framework completes
handler execution to allow caching modules to store responses to be used to handle
subsequent requests.

Application_AuthenticateRequest: Fired when the security module has established the
current user's identity as valid. At this point, the user's credentials have been validated.
Application_AuthorizeRequest: Fired when the security module has verified that a user
can access resources.

Session_Start: Fired when a new user visits the application Web site.

Session_End: Fired when a user's session times out, ends, or they leave the application
Web site.

Que:- What order they are triggered ?
Ans:- They're triggered in the following order:

* Application_BeginRequest
* Application_AuthenticateRequest
* Application_AuthorizeRequest
* Application_ResolveRequestCache
* Application_AcquireRequestState
* Application_PreRequestHandlerExecute
* Application_PreSendRequestHeaders
* Application_PreSendRequestContent
* Application_PostRequestHandlerExecute
* Application_ReleaseRequestState
* Application_UpdateRequestCache
* Application_EndRequest.

Que:- How can we force all the validation control to run ?
Ans:- Page.Validate

Que:- How can we check if all the validation control are valid and proper ?
Ans:- Using the Page.IsValid() property you can check whether all the validation are done.

Que:- Which JavaScript file is referenced for validating the validators at the client side ?
Ans:- WebUIValidation.js javascript file installed at “aspnet_client” root IIS directory is used
to validate the validation controls at the client side

Que:- What is Tracing in ASP.NET ?
Ans:- Tracing allows us to view how the code was executed in detail.

Que:- How do we enable tracing ?

Que:- How can we kill a user session ?
Ans:- Session.abandon

Que:- How do I send email message from ASP.NET ?
ANs:- ASP.NET provides two namespaces System.WEB.mailmessage classand
System.Web.Mail.Smtpmail class. Just a small homework create a Asp.NET project and
send a email at "Email Adress". Do not Spam.

Que:- Explain the differences between Server-side and Client-side code?
Ans:- Server side code is executed at the server side on IIS in ASP.NET framework, while
client side code is executed on the browser.