ADO.Net Interview Question and Answers
1.
|
What is Ado.NET?
|
ADO.NET is an object-oriented
set of libraries that allows you to interact with data sources.
ADO.NET is a set of classes that
expose data access services to the .NET programmer.
ADO.NET is also a part of the
.NET Framework.
ADO.NET is used to handle data
access.
ADO.NET is entirely based on
XML.
|
|
2.
|
What are the two fundamental
objects in ADO.NET?
|
There are two fundamental
objects in ADO.NET.
Datareader - connected architecture and Dataset - disconnected architecture. |
|
3.
|
What are the data access
namespaces in .NET?
|
The most common data access
namespaces :
System.Data
System.Data.OleDb
System.Data.SQLClient
System.Data.SQLTypes
System.Data.XML
System.Data.LINQ
|
|
4.
|
What are major difference
between classic ADO and ADO.NET?
|
In ADO the in-memory
representation of data is the recordset.A Recordset object is used to hold a
set of records from a database table.
In ADO.NET we have dataset.A DataSet is an in memory representation of data loaded from any data source. |
|
5.
|
What is the use of connection
object in ado.net?
|
|
The ADO Connection Object is
used to create an open connection to a data source. Through this connection,
you can access and manipulate a database.
|
||
6. What are the benefits of ADO.NET?
|
||
Scalability
Data Source Independence
Interoperability
Strongly Typed Fields
Performance
|
||
7.
|
What are the parts of ADO.NET?
|
ADO.NET is divided into the
Dataset object for manipulating disconnected data and the .NET Data Providers
for communicating with backend data stores and the Dataset.
|
|
8.
|
Whate are different types of
Commands available with DataAdapter ?
|
The SqlDataAdapter has
SelectCommand
InsertCommand
DeleteCommand
UpdateCommand
|
|
9.
|
What is the difference between
an ADO.NET Dataset and an ADO Recordset?
|
Dataset can fetch source data
from many tables at a time, for Recordset you can achieve the same only using
the SQL joins.
A DataSet can represent an
entire relational database in memory, complete with tables, relations, and
views, A Recordset can not.
A DataSet is designed to work
without any continues connection to the original data source; Recordset
maintains continues connection with the original data source.
DataSets have no current record
pointer, you can use For Each loops to move through the data. Recordsets have
pointers to move through them.
|
|
10.
|
What are the parameters that
control most of connection pooling behaviors?
|
Connect Timeout
Max Pool Size
Min Pool Size
Pooling
|
11.
|
What is a DataSet?
|
A DataSet is an in memory
representation of data loaded from any data source.
|
|
12.
|
What is a DataTable?
|
A DataTable is a class in .NET
Framework and in simple words a DataTable object represents a table from a
database.
|
|
13.
|
What is the data provider name
to connect to Access database?
|
Microsoft.Access
|
|
14.
|
Which namespaces are used for
data access?
|
System.Data
System.Data.OleDB
System.Data.SQLClient
|
|
15.
|
What is difference 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 the major components
of data provider?
|
The Connection
object which provides a connection to the database.
The Command
object which is used to execute a command.
The DataReader
object which provides a forward–only, read only, connected
recordset.
The DataAdapter
object which populates a disconnected DataSet with data and
performs update.
|
|
17.
|
What do you mean by Dataset?
|
A Dataset is a container where
all the rows fetched from a database table.
It is the job of DataAdapter to fill the Dataset with rows from the database. |
|
18.
|
What keyword is used to accept
a variable number of parameter in a method?
|
Params.
|
|
19.
|
What are the types of .Net
data providers?
|
The OLE DB.NET data provider
The SQL Server.NET data provider
|
|
20.
|
What are the advantage of
ADO.Net?
|
Database Interactions Are
Performed Using Data Commands
Data Can Be Cached in Datasets
Datasets Are Independent of Data
Sources
Data Is Persisted as XML.
|
|
21.
|
What is the difference between
OLEDB Provider and SqlClient ?
|
SQLClient .NET classes are
highly optimized for the .net / sqlserver combination and achieve optimal
results. The SqlClient data provider is fast. It's faster than the Oracle
provider, and faster than accessing database via the OleDb layer.
|
|
22.
|
What is the use of Parameter
Object?
|
In ADO Parameter object provides
information about a single parameter used in a stored procedure or query.
|
|
23.
|
What is DataAdapter?
|
DataSet contains the data from
the DataAdapter which is the bridge between the DataSet and Database.
DataAdapter provides the way to retrieve and save data between the DataSet
and Database. It accomplishes this by means of request to the SQL Commands
made against the database.
|
|
24.
|
What does ADO mean?
|
ADO stands for ActiceX Data
Objects.It was introduced few years ago as a solution to accessing data that
can be found in various forms, not only over a LAN but over the internet. It
replaced the data access technologies RDO(Remote Data Objects) and DAO (Data
Access Objects).
|
|
25.
|
Name some ADO.NET Objects?
|
Connection Object
DataReader Object
Command Object
DataSet Object
DataAdapter Object
|
|
26.
|
What is 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.
|
|
27.
|
What are the benefits of
ADO.NET?
|
ADO.NET offers several
advantages over previous versions of ADO and over other data access
components. These benefits fall into the following categories:
Interoperability
Maintainability
Programmability
Performance
Scalability
|
|
28.
|
How to creating a
SqlConnection Object?
|
SqlConnection conn = new
SqlConnection("Data Source=DatabaseServer;Initial Catalog=Northwind;User
ID=YourUserID;Password=YourPassword");
|
|
29.
|
How to creating a SqlCommand
Object?
|
It takes a string parameter that
holds the command you want to execute and a reference to a SqlConnection
object.
SqlCommand cmd = new SqlCommand("select CategoryName from Categories", conn); |
|
30.
|
How to load multiple tables
into dataset?
|
SqlDataAdapter da = new
SqlDataAdapter("Select * from Id; Select * from Salry", mycon);
da.Fill(ds); ds.Tables[0].TableName = "Id"; ds.Tables[1].TableName = "Salary"; |
|
31.
|
What is the difference between
SqlCommand and SqlCommandBuilder?
|
SQLCommand is used to retrieve
or update the data from database.
SQLCommandBuilder object is used to build & execute SQL (DML) queries like select insert update& delete. |
|
32.
|
What is the use of
SqlCommandBuilder?
|
SQL CommandBuilder object is
used to build & execute SQL (DML) queries like select insert update&
delete.
|
|
33.
|
How to copy the database from
one server to another server?
|
The easiest way to copy a
database from one server to another is to back up the database from the
source server in the form of SQL script and execute the SQL script on the
destination server to recreate database and its respective tables.
|
|
34.
|
What is LINQ?
|
LINQ is an acronym for the
Language Integrated Query and is a part of .NET framework.
It defines a set of Standard
Query Operators that enables us to query data in .NET supported languages.
|
|
35.
|
Explain ADO.Net Architecture?
|
ADO.NET provides the efficient
way to manipulate the database. It contains the following major components.
1. DataSet Object 2. Data Providers :
Connection Object
Command Object
DataReader Object
DataAdapter Object.
|
|
36.
|
What is the difference between
int and int32?
|
Both are same. System.Int32 is a
.NET class. Int is an alias name for System.Int32.
|
|
37.
|
What is the role of the
DataReader class in ADO.NET connections?
|
It returns a read-only,
forward-only rowset from the data source. A DataReader provides fast access
when a forward-only sequential read is needed.
|
|
38.
|
What are advantages and
disadvantages of Microsoft-provided data provider classes in ADO.NET?
|
SQLServer.NET data provider is
high-speed and robust, but requires SQL Server license purchased from
Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle,
DB2, Microsoft Access and Informix. OLE-DB.NET is a .NET layer on top of the
OLE layer, so it’s not as fastest and efficient as SqlServer.NET.
|
|
39.
|
What are acid properties?
|
Atomicity
Consistency
Isolation
Durability
|
|
40.
|
What is DataRowCollection?
|
Similar to DataTableCollection,
to represent each row in each Table we have DataRowCollection.
|
41.
|
What are basic methods of
Dataadapter?
|
Fill
FillSchema
Update
|
|
42.
|
What are the various methods
provided by the dataset object to generate XML?
|
ReadXML : Read’s a XML document in to Dataset.
GetXML : This is a function which returns the string containing XML document. WriteXML : This writes a XML data to disk. |
|
43.
|
What is DataSet Object?
|
Dataset is a disconnected,
in-memory representation of data. It can contain multiple data table from
different database.
|
|
44.
|
What is 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. |
|
45.
|
What is the role of DataReader
object?
|
A DataReader object provides
forward only, read only access to a database.
The connection to the database
must be open while accessing data through DataReader object.
It loads only a single row at a
time in the memory.
|
|
46.
|
Which architecture does
datasets follow?
|
Datasets follows the
disconnected data architecture.
|
|
47.
|
What is Serialization?
|
Serialization is the process of
persisting the state of an object after converting it into a stream of bytes.
The object can be persisted to a
file, a database or memory.
|
|
48.
|
What is Execute Non Query?
|
The ExecuteNonQuery() is one of
the most frequently used method in SqlCommand Object, and is used for
executing statements that do not return result sets (ie. statements like
insert data , update data etc.).
|
|
49.
|
What providers does Ado.net
uses?
|
The .NET Framework provides
mainly three data providers, they are
Microsoft SQL Server,
OLEDB,
ODBC.
|
|
50.
|
How will you close the
Database Conenction?
|
Always close both the DataReader
and database connection after access to the database is no longer required.
dbread.Close()
dbconn.Close()
|
|
51.
|
What is a Clustered Index?
|
The data rows are stored in
order based on the clustered index key.
Data stored is in a sequence of
the index.
In a clustered index, the physical
order of the rows in the table is the same as the logical (indexed) order of
the key values.
A table can contain only one
clustered index.
A clustered index usually
provides faster access to data than does a non-clustered index
|
|
52.
|
What is a Non–Clustered Index?
|
The data rows are not stored in
any particular order, and there is no particular order to the sequence of the
data pages.
In a clustered index, the
physical order of the rows in the table is not same as the logical (indexed)
order of the key values.
|
|
53.
|
What type of data model does
an OleDbCommand object fill?
|
An ADODataReader object.
|
|
54.
|
Which method do you invoke on
the DataAdapter control to load your generated dataset with data?
|
DataAdapter’ fill () method is
used to fill load the data in dataset.
|
|
55.
|
What is difference between
Dataset. clone and Dataset.copy?
|
Clone: - It only copies structure, does not copy data.
Copy: - Copies both structure and data. |
|
56.
|
What is DataAdapter?
|
A data adapter represents a set
of methods used to perform a two-way data updating mechanism between a
disconnected DataTable and the database. It aggregates four commands: select,
update, insert and delete command. One adapter can only generate and fill one
table in a DataSet.
|
|
57.
|
What is a Command Object?
|
The ADO Command object is used
to execute a single query against a database. The query can perform actions
like creating, adding, retrieving, deleting or updating records.
|
|
58.
|
What is basic use of DataView?
|
“DataView” represents a complete
table or can be small section of rows depending on some criteria. It is best
used for sorting and finding data with in “datatable”.
|
|
59.
|
What is the use of Connection
Object?
|
The ADO Connection Object is
used to create an open connection to a data source. Through this connection,
you can access and manipulate a database.
|
|
60.
|
What is a stored procedure?
|
A stored procedure is a
precompiled executable object that contains one or more SQL statements.
A stored procedure may be written to accept inputs and return output |
|
61.
|
What is Data Provider?
|
A set of libraries that is used
to communicate with data source. Eg: SQL data provider for SQL, Oracle data
provider for Oracle, OLE DB data provider for access, excel or mysql.
The data providers refers to a collection of objects that is responsible for providing and maintaining the connection to a database. |
|
62.
|
What is the provider and
namespaces being used to access oracle database?
|
system.data.oledb
|
|
63.
|
Which object is used to add a
relationship between Data table objects?
|
The DataRelation object is used
to add a relationship between Data table objects.
|
|
64.
|
What are the benefits of LINQ?
|
LINQ is available in all .NET
platform language such as C#.NET, VB.NET and F#.NET.
Easily transforms data into
objects and vice versa.
Reduce SQL injection attacks,
hence is more secure.
It makes it easier to extra data
from several data sources(XML, SQL, Objects etc).
Reduces the code size as it
provides relatively short codes for queries.
|
|
65.
|
What is the use of System.Data
namespace in ADO.Net?
|
System.Data:
This contains the basic objects used for accessing and storing relational data such as dataset,datatable and data relation. |
|
66.
|
What are managed providers?
|
A managed provider is analogous
to ODBC driver or OLEDB provider. It performs operation of communicating with
the database. ADO.NET currently provides two distinct managed providers. The
SQL Server managed provider is used with SQL server and is a very efficient
way of communicating with SQL Server. OLEDB managed provider is used to
communicate with any OLEDB compliant database like Access or Oracle.
|
|
67.
|
How do I delete a row from a
DataTable?
|
ds.Tables("data_table_name").Rows(i).Delete
dscmd.update(ds,"data_table_name") |
|
68.
|
What inside in DataSet?
|
Inside DataSet much like in
Database, there are tables, columns, constraints, relationships, views and so
forth.
|
|
69.
|
What is connection pooling?
|
Connection pooling refers to the
task of grouping database connection in cache to make them reusable because
opening new connections every time to a database is a time consuming process.
Therefore, connection pooling enables you to reuse already existing and
active database connections, whenever required, and increasing the
performance of your application.
|
|
70.
|
What is the use of Ado.net
connection?
|
Establishes a connection to a
specific data source.
|
|
71.
|
What is SqlConnection Object?
|
The connection object
establishes connection with a database.
It includes the information that
is required to connect with a database like the database server name, the
database name, user name, password and other parameters.
|
|
72.
|
What two classes are used to
read data only?
|
SqlDataReader
OldDbDataReader
classes to read data in a
forward directions only.
|
|
73.
|
What is SqlCommand Object?
|
The command object is used for
specifying the actions or commands to be executed on a database.
It uses the connection object
for identifying the database on which to execute commands.
|
|
74.
|
What is the use of System. XML
namespace in ADO.Net?
|
System. XML :
This contains the basic objects required to create read, store, write and manipulate XML documents according to W3C recommendations. |
|
75.
|
What is dataset Object?
|
The dataset object is used for
manipulating a memory image of a database.
The database object that is
loaded in memory and which is not connected with the physical database is
managed or manipulated through the dataset objects.
|
|
76.
|
What is SqlDataAdapter Object?
|
The object takes the help of all
the above objects to work with the underlying database.
It makes use of the connection
object to establish connection with the database, uses the command object to
execute Sql commands on the connected database.
|
|
77.
|
What is 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. |
|
78.
|
How would you connect to a
database by using .NET?
|
The connection class is used to
connect a .NET application with a database.
|
|
79.
|
What are the different methods
available under sqlcommand class to access the data?
|
ExecuteReader - Used where one or more records are returned -
SELECT Query.
ExecuteNonQuery - Used where it affects a state of the table and no
data is being queried - INSERT, UPDATE, DELETE, CREATE and SET queries.
ExecuteScalar - Used where it returns a single record.
|