String object is read only (immutable) that means string object cannot be modified .Some methods seems to modify the string object but actually they are not modifying the object but creating the new object.
String builder object is mutable ,it can modify the object by appending,removing,replacing etc.
Here when the object is modified it is refering to the same instance where as in string class a new object is creates
Performance:
Concat method of String class and Append Method of StringBuilder class both concatenate 2 strings.But the string class creates new object from existing object which allocates memory where as A StringBuilder object maintains a buffer to accommodate the concatenation of new data. New data is appended to the end of the buffer if room is available; otherwise, a new, larger buffer is allocated, data from the original buffer is copied to the new buffer, then the new data is appended to the new buffer.
2.Explain storage and performance in different Session Modes?
Storage location----------------
InProc - session kept as live objects in web server (aspnet_wp.exe)
StateServer - session serialized and stored in memory in a separate process(aspnet_state.exe). State Server can run on another machine
SQLServer - session serialized and stored in SQL server
Performance------------
InProc - Fastest, but the more session data, the more memory is consumed onthe web server, and that can affect performance.
StateServer - When storing data of basic types (e.g. string, integer, etc),in one test environment it's 15% slower than InProc. However, the cost ofserialization/deserialization can affect performance if you're storing lotsof objects.
SQLServer - When storing data of basic types (e.g. string, integer, etc),in one test environment it's 25% slower than InProc. Same warning aboutserialization as in StateServer.
Robustness-----------
InProc - Session state will be lost if the worker process (aspnet_wp.exe)recycles, or if the appdomain restarts. It's because session state isstored in the memory space of an appdomain. Read doc on when such eventswill happen.
StateServer - Solve the session state loss problem in InProc mode. Allowsa webfarm to store session on a central server. Single point of failure atthe State Server
.SQLServer - Similar to StateServer. Moreover, session state data cansurvive a SQL server restart
3. Difference between dataadapter and datareader?
Data Reader will read only one record at a time.So memory consumption will be less,it is purely connection oriented it will use connection exclusively when datareader is closed.the memory will be released on the server machine and connection will be used for any other purpose.Data Adapter acts as a mediator between dataset and database server.it will read data from the database server and places with in datasetthe manipulations on the dataset will be updated with the database server.
4.Difference between dataset and recordset?
1. Table Collection: ADO Recordset provides the ability tonavigate through a single table of information. That tablewould have been formed with a join of multiple tables andreturning columns from multiple tables. ADO.NET DataSet iscapable of holding instances of multiple tables. It has gota Table Collection, which holds multiple tables in it. Ifthe tables are having a relation, then it can be manipulatedon a Parent-Child relationship. It has the ability tosupport multiple tables with keys, constraints andinterconnected relationships. With this ability the DataSetcan be considered as a small, in-memory relational databasecache.
2. Navigation: Navigation in ADO Recordset is based on thecursor mode. Even though it is specified to be a client-sideRecordset, still the navigation pointer will move from onelocation to another on cursor model only. ADO.NET DataSet isan entirely offline, in-memory, and cache of data. All ofits data is available all the time. At any time, we canretrieve any row or column, constraints or relation simplyby accessing it either ordinarily or by retrieving it from aname-based collection.
3. Connectivity Model: The ADO Recordset was originallydesigned without the ability to operate in a disconnectedenvironment. ADO.NET DataSet is specifically designed to bea disconnected in-memory database. ADO.NET DataSet follows apure disconnected connectivity model and this gives it muchmore scalability and versatility in the amount of things itcan do and how easily it can do that.
4. Marshalling and Serialization: In COM, throughMarshalling, we can pass data from 1 COM component toanother component at any time. Marshalling involves copyingand processing data so that a complex type can appear to thereceiving component the same as it appeared to the sendingcomponent. Marshalling is an expensive operation. ADO.NETDataset and DataTable components support Remoting in theform of XML serialization. Rather than doing expensive
Marshalling, it uses XML and sent data across boundaries.
5. What are major events in GLOBAL.ASAX file ?
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. 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_PreSendContent: Fired before the ASP.NET page framework send content to a requesting client (browser).
Application_AcquireRequestState: Fired when the ASP.NET page framework gets the current state (Session state) related to the current request.
Application_ReleaseRequestState: Fired when the ASP.NET page framework completes execution of all event handlers. This results in all state modules to save their current state data.
Application_ResolveRequestCache: Fired when the ASP.NET page framework completes an authorization request. It allows caching modules to serve the request from the cache, thus bypassing handler execution.
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.
Session_End: Fired when a user's session times out, ends, or they leave the application Web site.
6.What order they are triggered ?
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.
7.How can we force all the validation control to run ?
Page.Validate
8.How can we check if all the validation control are valid and proper ?
Page.Isvalid()
9. How to disable client side script in validators?
Set EnableLcientsideScript to False
10. What is Tracing in ASP.NET ?
Tracing allows us to view how the code was executed in detail
11. How can we kill a user session ?
Session.abandon()
12. How do I sign out in forms authentication ?
FormsAuthentication.Signout()
13. If cookies are not enabled at browser end does form Authentication work?
No, it does not work.
14. What is the namespace in which .NET has the data functionality classes ?
Following are the namespaces provided by .NET for data management :-
System.data : This contains the basic objects used for accessing and storing relational data, such as DataSet,DataTable, and DataRelation. Each of these is independent of the type of data source and the way we connect to it.
System.Data.OleDB : It contains the objects that we use to connect to a data source via an OLE-DB provider, such as OleDbConnection, OleDbCommand, etc. These objects inherit from the common base classes, and so have the same properties, methods, and events as the SqlClient equivalents.
System.Data.SqlClient:
This contains the objects that we use to connect to a data source via the Tabular Data Stream (TDS) interface of Microsoft SQL Server (only). This can generally provide better performance as it removes some of the intermediate layers required by an OLE-DB connection.
System.XML
This Contains the basic objects required to create, read, store, write, and manipulate XML documents according to W3C recommendations.
15. What is difference between dataset and datareader ?
Following are some major differences between dataset and datareader :-
DataReader provides forward-only and read-only access to data, while the DataSet object can hold more than one table (in other words more than one rowset) from the same data source as well as the relationships between them.
Dataset is a disconnected architecture while datareader is connected architecture.
Dataset can persist contents while datareader can not persist contents, they are forward only.
16.What are major difference between classic ADO and ADO.NET ?
Following are some major differences between both
As in classic ADO we had client and server side cursors they are no more present in ADO.NET. Note it's a disconnected model so they are no more applicable.
Locking is not supported due to disconnected model.
All data persist in XML as compared to classic ADO where data persisted in Binary format also.
.How do you set the url of Hyperlink dynamically?
Using navigateurl property of hyperlink in code behind.
.What is resolveURL used for?
To get the relative path.
How do you get the current page name
Page.Request.Path
Get virtual path of current request from user control?
mybase.request.path
What is the main difference between Gridlayout and FlowLayout ?
GridLayout provides absolute positioning for controls placed on the page. Developers that have their roots in rich-client development environments like Visual Basic will find it easier to develop their pages using absolute positioning, because they can place items exactly where they want them. On the other hand, FlowLayout positions items down the page like traditional HTML. Experienced Web developers favor this approach because it results in pages that are compatible with a wider range of browsers. If you look in to the HTML code created by absolute positioning you can notice lot of DIV tags. While in Flow layout you can see more of using HTML table to position elements which is compatible with wide range of browsers.
Can you give a overview of ADO.NET architecture ?
The two central components of ADO.NET are : the DataSet, and the .NET Framework data provider, which is a set of components including the Connection, Command, DataReader, and DataAdapter objects.
The dataset is the core component of the disconnected architecture of ADO.NET. The DataSet is explicitly designed for data access independent of any data source. As a result it can be used with multiple and differing data sources, used with XML data, or used to manage data local to the application. The DataSet contains a collection of one or more DataTable objects made up of rows and columns of data, as well as primary key, foreign key, constraint, and relation information about the data in the DataTable objects.
The other important section in ADO.NET architecture is “Data Provider”. Data Provider provides access to datasource (SQL SERVER, ACCESS, ORACLE).In short it provides object to achieve functionalities like opening and closing connection, retrieve data and update data.
Connection object provides connectivity to a data source.
Command object enables access to database commands to return data, modify data, run stored procedures, and send or retrieve parameter information.
The DataReader provides a high-performance stream of data from the data source.
The DataAdapter provides the bridge between the DataSet object and the data source. The DataAdapter uses Command objects to execute SQL commands at the data source to both load the DataSet with data, and reconcile changes made to the data in the DataSet back to the data source Dataset object represents disconnected and cached data.
Difference between dataReader and Data Adapter
DataReader : Reads a forward-only, read-only stream of data from a data source.
DataAdapter : Populates a DataSet and resolves updates with the data source.
Explain DataSet?
The DataSet object is central to supporting disconnected, distributed data scenarios with ADO.NET
The DataSet represents a complete set of data including related tables, constraints, and relationships among the tables
The DataTableCollection
An ADO.NET DataSet contains a collection of zero or more tables represented by DataTable objects. The DataTableCollection contains all the DataTable objects in a DataSet.
A DataTable is defined in the System.Data namespace and represents a single table of memory-resident data. It contains a collection of columns represented by a DataColumnCollection, and constraints represented by a ConstraintCollection, which together define the schema of the table. A DataTable also contains a collection of rows represented by the DataRowCollection, which contains the data in the table. Along with its current state, a DataRow retains both its current and original versions to identify changes to the values stored in the row.
The DataRelationCollection
A DataSet contains relationships in its DataRelationCollection object. A relationship, represented by the DataRelation object, associates rows in one DataTable with rows in another DataTable. It is analogous to a join path that might exist between primary and foreign key columns in a relational database. A DataRelation identifies matching columns in two tables of a DataSet.
Relationships enable navigation from one table to another within a DataSet. The essential elements of a DataRelation are the name of the relationship, the name of the tables being related, and the related columns in each table. Relationships can be built with more than one column per table by specifying an array of DataColumn objects as the key columns. When a relationship is added to the DataRelationCollection, it may optionally add a UniqueKeyConstraint and a ForeignKeyConstraint to enforce integrity constraints when changes are made to related column values.
ExtendedProperties
The DataSet (as well as the DataTable and DataColumn) has an ExtendedProperties property. ExtendedProperties is a PropertyCollection where you can place customized information, such as the SELECT statement that was used to generate the resultset, or a date/time stamp of when the data was generated. The ExtendedProperties collection is persisted with the schema information for the DataSet (as well as the DataTable and DataColumn).
http://www.blogger.com/””> Check details
What are the different data providers provided by .Net framework?
.NET Framework Data Provider for SQL Server :
For Microsoft® SQL Server™ version 7.0 or later.
.NET Framework Data Provider for OLE DB:
For data sources exposed using OLE DB.
.NET Framework Data Provider for ODBC
.NET Framework Data Provider for Oracle
For Oracle data sources.
What is command builder object?
A helper object that will automatically generate command properties of a DataAdapter or will derive parameter information from a stored procedure and populate the Parameters collection of a Command object
What are the execute methods of command Object?
The Command object exposes several Execute methods you can use to perform the intended action. When returning results as a stream of data, use ExecuteReader to return a DataReader object. Use ExecuteScalar to return a singleton value. Use ExecuteNonQuery to execute commands that do not return rows.
How do you determine whether dataReader has returned rows or not?
The .NET Framework version 1.1 includes an additional property for the DataReader, HasRows, which enables you to determine if the DataReader has returned any results before reading from it.
Can I access the values return by dataReader before it is closed?
NO,You should always call the Close method when you have finished using the DataReader object.
If your Command contains output parameters or return values, they will not be available until the DataReader is closed.
Can we Handle Multiple result sets in datareader?
Yes, the DataReader provides the NextResult method to iterate through the result sets in order
Expalin briefly about DataAdapter Object?
. A DataAdapter is used to retrieve data from a data source and populate tables within a DataSet. Each .NET Framework data provider included with the .NET Framework has a DataAdapter object.
SQL Server includes a SqlDataAdapter object
OLE DB includes an OleDbDataAdapter object
The DataAdapter also resolves changes made to the DataSet back to the data source. The DataAdapter uses the Connection object of the .NET Framework data provider to connect to a data source and Command objects to retrieve data from and resolve changes to the data source.
The InsertCommand, UpdateCommand, and DeleteCommand properties of the DataAdapter are Command objects that manage updates to the data in the data source according to modifications made to the data in the DataSet.
The Fill method of the DataAdapter is used to populate a DataSet with the results of the SelectCommand of the DataAdapter. The Fill method uses the DataReader object implicitly to return the column names and types used to create the tables in the DataSet, as well as the data to populate the rows of the tables in the DataSet
Fill method automatically opens the connection the adapter using and also closes it when the job is done,which is entirely different form data reader
DataAdapter exposes 3 different events.
RowUpdating : An UPDATE, INSERT, or DELETE operation on a row (by a call to one of the Update methods) is about to begin.
RowUpdated : An UPDATE, INSERT, or DELETE operation on a row (by a call to one of the Update methods) is complete
FillError : An error has occurred during a Fill operation
The RowUpdatingEventArgs and RowUpdatedEventArgs arguments passed to the RowUpdating and RowUpdated events include: a Command property that references the Command object being used to perform the update; a Row property that references the DataRow object containing the updated information; a StatementType property for what type of update is being performed; the TableMapping, if applicable; and the Status of the operation.
Status property to determine if an error has occurred during the operation
Continue - Continue the update operation
ErrorsOccurred- Abort the update operation and throw an exception
SkipCurrentRow- Ignore the current row and continue the update operation
SkipAllRemainingRows- Abort the update operation but do not throw an exception
We use ContinueUpdateOnError property to handle errors for updated rows
DataAdapter.ContinueUpdateOnError is true, when an update to a row results in an exception being thrown the text of the exception is placed into the RowError information of the particular row and processing continues without throwing an exception. This enables you to respond to errors when the Update is complete, in contrast to the RowUpdated event that enables you to respond to errors when the error is encountered.
Explain FillError event ?
The DataAdapter issues the FillError event when the data in the row being added could not be converted to a .NET Framework type without some loss of precision.
What is the use of command objects and what are the methods provided by the command object ?
They are used to connect connection object to Datareader or dataset. Following are the methods provided by command object :-
ExecuteNonQuery :- Executes the command defined in the CommandText property against the connection defined in the Connection property for a query that does not return any row (an UPDATE, DELETE or INSERT). Returns an Integer indicating the number of rows affected by the query.
ExecuteReader :- Executes the command defined in the CommandText property against the connection defined in the Connection property. Returns a "reader" object that is connected to the resulting rowset within the database, allowing the rows to be retrieved.
ExecuteScalar :- Executes the command defined in the CommandText property against the connection defined in the Connection property. Returns only single value (effectively the first column of the first row of the resulting rowset) any other returned columns and
What are basic methods of DataAdapter ?
Fill :- Executes the SelectCommand to fill the DataSet object with data from the data source. It an also be used to update (refresh) an existing table in a DataSet with changes
made to the data in the original datasource if there is a primary key in the table in the DataSet.
FillSchema :- Uses the SelectCommand to extract just the schema for a table from the data source, and creates an empty table in the DataSet object with all the corresponding constraints.
Update:- Calls the respective InsertCommand, UpdateCommand, or DeleteCommand for each inserted, updated,or deleted row in the DataSet so as to update the original data source with the changes made to the content of the DataSet. This is a little like the UpdateBatch method provided by the ADO Recordset object, but in the DataSet it can be used to update more than one table.
What are the various objects in Dataset ?
Dataset has a collection of DataTable object within the Tables collection.
Each DataTable object contains a collection of DataRow objects and a collection of DataColumn objects. There are also collections for the primary keys, constraints, and default values used in this table which is called as constraint collection, and the parent and child relationships between the tables(DataRelationship Collection). Finally, there is a DefaultView object for each table. This is used to create a DataView object based on the table, so that the data can be searched, filtered or otherwise manipulated while displaying the data.
How do we Execute stored procedure in ADO.NET?
To execute stored procedures in .Net ,we use the command object and set the commandtype property to Stored procedure.
How to close database connection after datareader is closed ?
Command method Executereader takes a parameter called as CommandBehavior where in we can specify saying close connection automatically after the Datareader is close
objDataReader =objCommand.ExecuteReader(CommandBehavior.CloseConnection)
How do you return schema information form data reader?
Set the Parameter of ExecuteReader method of Command object to SchemaOnly.
objDataReader =objCommand.ExecuteReader(CommandBehavior.Schemaonly)
How to track the changes in dataset?
For tracking down changes Dataset has two methods
“GetChanges “and “HasChanges”.
GetChanges Returns dataset which are changed since it was loaded or since Acceptchanges was executed.
HasChanges This property indicates that dataset has any changes been made since the dataset was loaded or acceptchanges method was executed. If we want to revert or abandon all changes since the dataset was loaded use “RejectChanges”.
What are the new features of ASP.net 2.0 ?
Master Pages:
Lets you easily create pages with consistent elements such as
banners and navigation elements.
Site navigation
Provides controls that make it easy to create site navigation
Themes
Let you easily customize formatting elements like fonts and colors.
New data-access features
New data source controls and data-bound controls drastically
reduce the amount of code required for most database applications
Login
Provides controls that let you manage user logins to your web sites.
Profiles
Uses a database to store data about users between sessions.
Web parts
Lets the user choose which elements to include in a web page.
What are the new features of ASP.net 3.5 ?
Two new data access controls are included with the
ASP.NET 3.5: the ListView and DataPager controls.
The Microsoft AJAX (Asynchronous JavaScript and
XML) extensions are integrated into the ASP.NET 3.5.
AJAX represents a transition from using server-side
technologies to using client-side technologies when
building we applications. By using ASP.NET AJAX, you
can improve the user experience and the efficiency of your
Web applications.
Microsoft LINQ to SQL is a new query language that you
to access a database without writing any SQL.
Maximum Number of Colums allowed in a table
1024
Maximum number of parameters in a stored procedure
2100.
Thanks for this post Harika.
ReplyDeleteIt's very much Informative and the poeple who are attending interviews will definitely find this useful.