ADO.NET Interview Questions and Answers (445) - Page 6

Does SQLClient and OLEdb class share the same functionality ?

No, each have its own functionality,

Ex : for sql client , there is SqlConnection object

and for oledb client , there is OleDBConnection
How do you connect to SQL Server Database without using sqlclient ?

You can connect to SQL Server Database without using sqlclient by using oledb namespace.

Example:

<%@ Import Namespace="System.Data.OleDb" %>


<script runat="server">
sub Page_Load
dim dbconn
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=" & server.mappath("northwind.mdb"))
dbconn.Open()
end sub
</script>

Explain about Db enumerator ?

Db enumerator base class is added to ADO.NET 2.0.
This class facilitates the process of obtaining a list of data sources. SQL server returns instances that are available on the network. Programmers do have choice of tools in their hands with this feature.
What are the performance considerations when using dataset ?

Since there is no memory buffer is maintained by the data reader, it takes up fewer resources and performs more efficiently with small number of data operations.
The dataset, on the other hand is more efficient when large number of updates are to be made to the database. All the updates are done in the local memory and are updated to the database in a batch. Since database connection remains open for the short time, the database management system does not get flooded with the incoming requests.
However, since the dataset stores the records in the local buffer in the hierarchical form, it does take up more resources and may affect the overall performance of the application.
Can dataReader hold data from multiple tables ?

Data reader can hold data from multiple tables and datareader can hold more than one table.

Example:

string query="select * from employee; select * from student";

sqlcommand cmd=new sqlcommand(query, connection);
sqldatareader dr=cmd.executeReader();
if(dr.hasrows)
{
dr.read();
gridview1.DataSource=dr;
gridview1.Databind();
if(dr.nextresult)
{
gridview2.datasource=dr;
gridview2.databind();
}
}
dr.colse();
connection.close();

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 ado.net 2.0 called MARS using Mars in connection string we can do it.

Example:

cn.ConnectionString = "server=(local); database=employee; integrated security=sspi; MultipleActiveResultSets=True";

Why edit is not possible in repeater ?

Edit is not possible in repeater because, it is used to read the data from the DB as Read-only manner, only forward direction not backward..hence it does not support edit operation.
In simple words, Repeater Control just reads the information from the database,so edit is not possible.
Can we connect two datareader to same data source using single connection at same time ?

Yes, it is possible to connect two datareader to the same datasource, but the main thing is, you have to close the first datareader before using the second one. Then only it is possible.
What is typed and untyped dataset ?

A DataSet can be Typed or Untyped. The main difference between the two lies is that, a Typed DataSet has a schema and an Untyped DataSet does not have one.
It should be noted that the Typed Datasets have more support in Visual studio.
How can you find a problem in the data stack ?

Problem can arise from these following instances they are: -

1) Mismatch of schema between the client and database.
2) Network library problems or non existence of data.
3) Wrong SQL generated.
4) Wrong programming logic.
Explain the Differences between OLEDB SQL SERVER, OLEDBDOTNET PROVIDER ?

OleDBDotNet Provider can be used to connect to any DataSource.
OleDb SQL SERVER can be used to connect only to a SQL Server DataSource.
What is different between SqlCommand object and Command Behavior Object ?

.NET Command Object - The Command object is similar to the old ADO command object.

It is used to store SQL statements that need to be executed against a data source.

The Command object can execute SELECT statements, INSERT, UPDATE, or DELETE statements, stored procedures, or any other statement understood by the database.
What is the Dot Net Framework data provider for OLEDB ?

The dot net framework data provider for OLEDB provides connectivity with the OLEDB supported database management systems. It is the recommended middle tier for the SQL Server 6.5 or earlier and Microsoft Access Database. It is a general data provider. You can also use it to connect with the SQL Server or Oracle Database Management Systems.
The classes for this provider are present in the System.Data.OleDBClient namespace.
What is the difference between an ADO.NET Dataset and an ADO Recordset ?

The differences between ADO.NET Dataset and an ADO Recordset are as follows :

1) Dataset can fetch source data from many tables at a time, whereas for Recordset you can achieve the same only using the SQL joins.

2) A DataSet can represent an entire relational database in memory, complete with tables, relations, and views. A Recordset cannot do the same.

3) A DataSet is designed to work without any continuous connection to the original data source. Recordset maintains continuous connection with the original data source.

4) DataSets have no current record pointer, you can use For Each loops to move through the data. Recordsets have pointers to move through them.
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 is always a good habit to either call the close or dispose method of the connection as soon as you have finished work with the connection object.
How to enable and disable connection pooling ?

For .NET this connection pooling is enabled by default but if you want to just make sure set Pooling = true in the connection string.
To disable connection pooling, set Pooling = false in connection string if it is an ADO.NET Connection.
If it is an OLEDBConnection object set OLE DB Services = -4 in the connection string.
What are the steps involved to fill a dataset? Write the code for the same?

Steps to fill a dataset.

a. Create a connection object.
b. Create an adapter by passing the string query and the connection object as parameters.
c. Create a new object of dataset.
d. Call the Fill method of the adapter and pass the dataset object.

Example:
using System.Data;

using System.Data.SqlClient;

SqlConnection conn = new SqlConnection("server=localhost;Database=MyDB;userid=sa;pwd=sa");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from table1", con);
DataSet ds = new DataSet();
da.Fill(ds);

In which conditions usage of SqlDataReader is better than Dataset and vice-versa ?

Use SqlDataReader in the following conditions

•If you want to reduce the memory footprint of your application.

•Want to avoid the object creation overhead associated with the DataSet.

•Want to streamline and optimize your data access.

•Want to read row which contains BLOB (binary large object) columns.

•Wan to perform data binding with a control that support a data source which implement IEnumerable .

Use Dataset in the below condition

•Want in-memory relational view of the data for xml or non-xml manipulation.

•Want to retrieved data from multiple data source s like table,files or databases.

•Want to use the batch update facilities.

•Want to disconnected memory-resident cache of data.

•Wan to perform data binding with a control that support a data source which implement IList .
What is EntityObject Generator ?

It is a T4 template you can use to generate entity classes that enable u to customize the entities that are created by actually modifying the template that generates the VB or c# code.

Microsoft include various T4 templates in Visual studio for rapid development. T4 template has a TT extension,which stands for Text template.
What is the use of the Connection object?

•An OleDbConnection object is used with an OLE-DB provider.
•A SqlConnection object uses Tabular Data Services (TDS) with MS SQL Server.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories