Sunday, 3 April 2011

Ado.Net FAQ's

can we connect two dataadapters to same data source using single connection at same time?

yes,we can connect two dataadapters to same datasource using single connection at same time.
There is a technology in 2.0 called MARS usinng Mars in connection string we can do it.
for eg:
cn.ConnectionString = "server=(local); database=employee; integrated security=sspi; MultipleActiveResultSets=True";

What are the two fundamental objects in ADO.NET ?

Datareader and Dataset are the two fundamental objects in ADO.NET.

What are major difference between classic ADO and ADO.NET ?

a. In classic ADO their is client and server side  cursors which is not available in ADO.NET.
b. Their is no concept of locking in
c. All data is persisted in XML as compared to classic ADO where data was persisted in Binary format also.

what is the difference between recordset and DataSet?

There two main basic differences between recordset and dataset :

a. In dataset we can retrive data from two databases but in recordset its not possible.
b. All representation of Dataset is using XML while recordset uses COM.
c. We cannot transmit Recordset on HTTP while Dataset can be.

What is the difference between connected and disconnected architecture?

1. In connected architecture state of connection constantly remains open but in disconnected data is fetched
   in client side.
2. Connected architecture has low scalability then disconnected architecture.
3. In connected current data is always available but in disconnected up to data data is not available.
4. Connected uses datareader whereas disconnected uses dataset.

Does disconnected architecture requires manual opening and closing of connection?

No, We dont have to do manula opening and closing in disconnected it is required in connected architecture.
In disconnected architecture datadapter does it internally.

Ado.Net basic questions

What is the namespace in which .NET has the  data functionality classes ?

Following are the namespaces provided by .NET for data management :-

System.Data: Has DataSet,DataTable, and DataRelation.

System.Data.OleDB: Has OleDbConnection, OleDbCommand, etc.

System.Data.SqlClient: SqlConnection, SqlCommand, SqlDataAdapter etc.

System.XML This Contains the basic objects required to create, read, store, write, and manipulate XML documents.

What is the use of connection object ?

They are used to connect a data to a Command object.

a. An OleDbConnection object is used with an OLE-DB provider
b. A SqlConnection object uses Tabular Data Services (TDS) with MS SQL Server

What is the use of command objects and what are the methods provided by the command object ?

Used to connect connection object with Datareader or dataset.Following are the methods provided by command object :-

a. ExecuteNonQuery :- Used for a query that does not return any rows (an UPDATE, DELETE or INSERT).Returns an Integer indicating the number of  rows affected by the query.
b. ExecuteReader :- Return a "reader" object that is connected to the resulting rowset within the database, allowing the rows to be retrieved.
c. ExecuteScalar :- Returns only a single value (effectively the first column of the first row of the resulting rowset). Any other returned column and rows are discarded.

If we are not returning any records from the database, which method is to be used?

There is a method called Execute Non Query. This method executes the Update, Delete etc. This does not return any rows but will give the number of rows affected.

Explain ExecuteNonQuery?

Executes a Transact-SQL statement against the connection and returns the number of rows affected.

What is the ExecuteScalar method?

Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.


DataAdapter Interview questions

What is the use of dataadapter ?

These are objects that connect one or more Command objects to a Dataset object..They provide logic that gets the  data from the data store and populates the tables in the DataSet, or pushes the changes in the DataSet back into the data store.

What are basic methods of Dataadapter ?

There are three most commonly used methods of Dataadapter :

Fill :- Executes the SelectCommand to fill the DataSet object with data from the data source. Can 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.

DataAdapter is used in Connected or Disconnected architecture?
It is used in disconnected architecture.