Professional Documents
Culture Documents
ADO.Net is one of the major component of .Net Framework, which is designed to connect to
databases like Oracle, MySQL, SQL Server, MS Access etc. and work with data stored in them.
ADO.Net provides in built classes to connect with Databases like Oracle, MySQL, SQL
Server, MS Access etc.
Provides in built classes to do data manipulation operations like Insert, Update, Delete
and Select data.
Provides data providers for specific databases for efficient interactions with DB. Example
- ODP.Net provider for Oracle.
Tight integration with XML
Provides functionality to combine data from different data sources
Disconnected Data architecture for better performance
Batch Update – To update n no of rows in a database table in a single call from a program
thus by avoiding round trip to database.
Data Paging – To read data from a certain index
Connection Details – To get detailed info about connections like buffer information,
cursor details etc.
DataSet.RemotingFormat Property – To make dataset serialized in Binary
DataTable's Load and Save Methods – For XML interactions.
ADO
ADO.Net
Fundamental Objects of ADO.Net are DataReader and DataSet. DataSet Object can have a set of
DataTables and relationships between these tables. DataSet can be used in disconnected
connection with DB. DataReader is used to read the read only data from a database.
DataReader is used to fetch data from a database in a much faster way. Since the rows are
fetched one at a time, load on the network will be low. Since DataReader is read only,
transactions are not allowed. Since it support forward only data iteration, random data fetch is
not supported.
using System.Data.SqlClient;
try
{
// Open DB connection
string Connection = "server=localhost; uid = UserName ; pwd = Password ;
database = DemoDB";
SqlConnection conn = new SqlConnection(Connection);
conn.Open();
}
catch ( Exception ex )
{
// Log Exceptions
}
finally
{
conn.Close ( ) ; // Close the connection
}
When one or more related SQL Commands are executed and if any one statement failed to
execute, we need to rollback the entire related operations that has been executed. In such a
scenario, Transactions are used.
using System.Data.SqlClient;
try
{
string Connection = "server=localhost; uid = UserName ; pwd = Password ;
database = DemoDB";
SqlConnection con = new SqlConnection(Connection);
con.Open();
All simple Transactions are ReadCommitted by default. If two persons are accessing the same
table and if one person executes an insert statement, another person will be able to access the
newly inserted row only after the first person commit the transaction. If a transaction is set as
ReadUncommited, in the two person scenario second person will be able to read the information
inserted by first person before he commits the transaction.
SQLCommand in simple terms is a collection of strings containing SQL statements which will
be send to database for various operations. SQL Commands can be of type Select, Insert,
Delete,Update or Stored procedures.
14) What are the different execution methods provided by the command object ?
After creating an SQL or OLEDb Command, it needs to be executed. Following methods are
used to execute SQL Commands.
ExecuteNonQuery() – Used to execute the command which did not return any output
ExecuteReader() – Used to execute the command which return a typed IDataReader
ExecuteScalar() – Used to execute the commands which return a single value
ExecuteXmlReader() – Used to execute the command that returns an XmlReader object.
The object can be used to traverse the XML fragment returned from DB.
The DataSet is used to store data from a data source . It consists of a set of data tables. We can
also specify the relation between the tables inside a dataset.
Data Table is used to store the data retrieved from a database in application memory. Data table
will have a set of data columns and data rows. Data table supports operations like adding,
updating and deleting a row.
Pessimistic locking is used when the user wants to update a record in a database and the user
want to prevent other users from updating the same record. Other user’s can only view the data
when there is pessimistic locking. Optimistic locking is used to improve concurrent operations
on a record by allowing multiple users to update the same record. The record is only locked
when updating the record. Optimistic locking has been widely used by web developers.
Dataset.Clone only copies the schema of a DataSet object like relations between data tables and
constraints. Dataset.Copy copies both the data and structure of a DataSet object.
Use Pooling = true in connection string if we want to enable connection pooling. To disable
connection pooling set Pooling = false .
Language-Integrated Query (LINQ) is one of the advanced featured provided by .Net. LINQ
provides native query language for C# and VB.Net to update and retrieve data from different
data sources like SQL Server Database,XML etc.
.NET Framework Data Provider for SQL Server – For connecting .Net application with
SQL Server. Namespace used for SQL Server Connectivity is System.Data.SqlClient
namespace.
Data Provider for SQL Server Compact 4.0 - For connecting .Net application with SQL
Server Compact 4.0. Namespace used for SQL Server Compact 4.0 Connectivity is
System.Data.SqlServerCe
.NET Framework Data Provider for OLE DB – For connecting .Net application with data
sources exposed by OLE. Namespace used for OLE DB Connectivity is
System.Data.OleDb namespace.
.NET Framework Data Provider for ODBC – For connecting .Net application with data
sources exposed by ODBC. Namespace used for ODBC Connectivity is
System.Data.Odbc namespace.
.NET Framework Data Provider for Oracle – For connecting .Net application with Oracle
database 8.1.7 or later. Namespace used for oracle Connectivity is
System.Data.OracleClient namespace.
EntityClient Provider - For connecting .Net application with Entity Data Model (EDM)
applications. Namespace used for EDM Connectivity is System.Data.EntityClient
namespace
Command is used to execute all kind of SQL queries like data manipulation languages(DML)
and Data definition language(DDL). DML operations are SELECT, INSERT, UPDATE, and
DELETE. DDL operations are Create and drop tables. Command Builder object is used to build
and execute DML queries like select, insert and delete table.
ReadXml(Stream) – Uses System.IO.Stream to read XML schema and data into the
DataSet
ReadXml(String) – Reads XML data from the specified file.
ReadXmlSchema() – Reads XML schema from the specified file.
GetXml() – Get XML data in a Dataset as a single string.
GetXmlSchema() – Get XSD Schema in a Dataset as a single string.
WriteXml() – Writes the contents of Dataset to the specified file.
WriteXmlSchema() – Writes XSD Schema into the specified file.
Typed datasets have associated schema file. Error checking will be done during design time with
respect to schema. It also use explicit names and data types for their members. Untyped dataset
uses table and column collections for their members. There wont be any error checking
associated with Untyped Dataset, since they are populated at runtime.
31) What are the parameters that control most of connection pooling behaviors ?