ADO .NET

What is Maximum Pool Size in ADO.NET Connection String?

Maximum pool size decides the maximum number of connection objects to be pooled. If the maximum pool size is reached and there is no usable connection available the request is queued until connections are released back in to pool. So it’s always a good habit to call the close or dispose method of the connection as soon as you have finished work with the connection object.

Explain in detail the fundamental of connection pooling?

When a connection is opened first time a connection pool is created and is based on the exact match of the connection string given to create the connection object. Connection pooling only works if the connection string is the same. If the connection string is different, then a new connection will be opened, and connection pooling won’t be used.

Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?

There two main basic differences between recordset and dataset :-

  • With dataset you an retrieve data from two databases like oracle and sql server and merge them in one dataset , with recordset this is not possible
  • All representation of Dataset is using XML while recordset uses COM.
  • Recordset can not be transmitted on HTTP while Dataset can be.

What is difference between Dataset. clone and Dataset. copy ?

Clone: – It only copies structure, does not copy data.

Copy: – Copies both structure and data.

How can we perform transactions in .NET?

The most common sequence of steps that would be performed while developing a transactional application is as follows:

  • Open a database connection using the Open method of the connection object.
  • Begin a transaction using the Begin Transaction method of the connection object. This method provides us with a transaction object that we will use later to commit or rollback the transaction. Note that changes caused by any queries executed before calling the Begin Transaction method will be committed to the database immediately after they execute. Set the Transaction property of the command object to the above mentioned transaction object.
  • Execute the SQL commands using the command object. We More >

What’s difference between “Optimistic” and “Pessimistic” locking ?

In pessimistic locking when user wants to update data it locks the record and till then no one can update data. Other user’s can only view the data when there is pessimistic locking.

In optimistic locking multiple users can open the same record for updating, thus increase maximum concurrency. Record is only locked when updating the record. This is the most preferred way of locking practically. Now a days browser based application is very common and having pessimistic locking is not a practical solution.

What is the use of CommandBuilder ?

CommandBuilder builds “Parameter” objects automatically. Below is a simple code which uses commandbuilder to load its parameter objects.

Dim pobjCommandBuilder As New OleDbCommandBuilder(pobjDataAdapter) pobjCommandBuilder.DeriveParameters(pobjCommand)

Be careful while using “DeriveParameters” method as it needs an extra trip to the Datastore which can be very inefficient.

How can we add relation’s between table in a DataSet ?

Dim objRelation As DataRelation

objRelation=New

DataRelation(“CustomerAddresses”,objDataSet.Tables(“Customer”).Columns(“Custid”) ,objDataSet.Tables(“Addresses”).Columns(“Custid_fk”))

objDataSet.Relations.Add(objRelation)

Relations can be added between “DataTable” objects using the “DataRelation” object. Above sample code is trying to build a relationship between “Customer” and “Addresses” “Datatable” using “CustomerAddresses” “DataRelation” object.

How can we load multiple tables in a DataSet ?

objCommand.CommandText = “Table1″

objDataAdapter.Fill(objDataSet, “Table1″) objCommand.CommandText = “Table2″ objDataAdapter.Fill(objDataSet, “Table2″)

Above is a sample code which shows how to load multiple “DataTable” objects in one “DataSet” object. Sample code shows two tables “Table1” and “Table2” in object ObjDataSet.

lstdata.DataSource = objDataSet.Tables(“Table1″).DefaultView

In order to refer “Table1” DataTable, use Tables collection of DataSet and the Defaultview object will give you the necessary output.

What is the difference between “DataSet” and “DataReader” ?

Fourth point is the answer to the twist.

Note:- This is my best question and I expect everyone to answer it. It is asked almost 99% in all companies….Basic very Basic cram it.

Following are the major differences between “DataSet” and “DataReader” :-

  • “DataSet” is a disconnected architecture, while “DataReader” has live connection while reading data. If we want to cache data and pass to a different tier “DataSet” forms the best choice and it has decent XML support.
  • When application needs to access data from more than one table “DataSet” forms the best choice.
  • If we need to move back while reading records, “datareader” does not support this More >