Sei sulla pagina 1di 15

Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution

Agenda
1 ADO.NET ARCHITECTURE
2 Layers of ADO.NET
4 New Features in ADO.NET 2.0

3 Improving Performance of
ADO.NET

5 LINQ On ADO.NET



6 Factors Affecting the
Performance of ADO.Net

Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
ADO.NET DATA Architecture
ADO.NET Components
1> .NET Framework data providers
2> The DataSet



Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
Types Of Connections To DataBase
Connected Model
1)Connection
2)Command
3)Data Reader

Disconnected Model

1)Connection
2)Data Adapter
3)Data Set

Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
Layers and Executing Commands of ADO.NET
Layers to Data Access in ADO .Net
1.The Physical Data store
2.The Data provider
3.The Data Set
4.The Data View

Executing Commands on a Database
1.Execute Scalar
2.Execute Non Query
3.Execute Reader
Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
Improving ADO .NET Performance Using Compiled Query
Choosing between Data Adapter and Command
Object
Data Adapter is useful whenever the amount of data to be transferred between the
application and the database is less and the number of rows to be updated or
inserted is less.
Compiling the query increases the performance of the data updating process. More
than 50% increase in the performance was seen when compiled query was used to
update data against the data updating done using normal query or Data Adapter.


Source
Database
Tabel1
Target
Database
Tabel1
Prepare the Insert/Update
parameterized Query for the
target DB.
Compile the Query using
Command.Prepare()
fetch the data using Reader
For each row fetched, prepare
the parameters values.
Execute the Compiled query on
the target database (using
Command.Execute()).
Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
New Features in ADO.NET 2.0
1. Server Enumeration
Provides support for enumerating active instances of Microsoft SQL Server
2000 and 2005 as well.
SqlDataSourceEnumerator class exposes the information to the developer
about list server instances available on the network that matches the list provided
when a user attempts to create a new connection, and expands the drop-down list
containing all the available on the Connection Properties dialog box.

Ex: public sealed class SqlDataSourceEnumerator : DbDataSourceEnumerator
2. Bulk Copy Operations
Enables you to perform fast bulk inserts using the .NET Data Provider for SQL
Server.
example:
SqlBulkCopy bulkCopy = newSqlBulkCopy(con)
bulkCopy.DestinationTableName=table name;
bulkCopy.WriteToServer(reader);
Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
Contd..

3. Multiple Active Result Sets (MARS)
Multiple Active Result Sets (MARS) is a new feature that works with SQL Server 2005 to
allow the execution of multiple batches on a single connection
Allows an application to have more than one SqlDataReader open on a connection when each
instance of SqlDataReader is started from a separate command. However, when MARS is
enabled for use, each command object used adds a session to the connection.

Example:
SqlConnection con=new SqlConnection( connection string + MultipleActiveResultSets=true );
SqlCommand cmd1=new SqlCommand(command1,con);
SqlCommand cmd2=new SqlCommand(command2,con);
SqlDataReader dr1=cmd1.ExecuteReader();
While(dr1.Read())
{
SqlDataReader dr2=cmd2.ExecuteReader()
While(dr2.Read())
{

}
}


Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
Contd..
4. New SQL Server Max Data Types
Provides support for varchar(max), nvarchar(max), varbinary(max) data types
in SQL Server 2005.
Large Object(LOB) data types does not exceed the maximum row size of 8
kilobytes (KB) in sql server2000 ,where as sql server 2005, it is 2^32 bytes.
5.Batch Processing
Enhances application performance by reducing the number of round-trips to
the database when applying updates from the DataSet.
Example:
Open Connection;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.UpdateCommand =new SqlCommand(commandString,con);
adapter.InsertCommand =new SqlCommand(commandString,con);
adapter.DeleteCommand =new SqlCommand(commandString,con);
adapter.UpdateBatchSize = batchSize;
adapter.Update(dataTable);






Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
contd..
6.DataSet Enhancements
The new DataTableReader presents the contents of a DataSet or a DataTable
in the form of one or more read-only, forward-only result sets.
Example:
DataTable Table1= getTable1();
DataTable Table2 = getTable2();
//getTable are methods which return Datatable after executing operations to add
columns and rows in that table
DataTableReader reader = new DataTableReader(new Data Table[ ] { Table1,Table2};
Do
{
Printmethod(reader);
} while(reader.NextResult());
Printmethod(DataTableReader reader)
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
Console.Write(reader[i] + " ");
}
}
}
Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
Contd..
7.Create a DataTable from a DataView
You can now create a DataTable from a DataView. The new DataTable will have
the same set of rows as the current Data View.
Optionally the columns of the new DataTable can be a subset of the DataView
columns.
DataView.ToTable() which Creates and returns a new DataTable based on rows in an
existing DataView.


8. DataTable as a Stand-Alone Object
Many methods that were only available in the DataSet in previous versions are
now available in the DataTable as well (such as ReadXml and WriteXml).
Also, a DataTable can be serialized by itself, so its no longer necessary to
have a DataSet with a single table just to expose the table through Web services or
any other mechanism that requires serialization.




Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
Contd..
9.Row State Control
The new SetAdded and SetModified methods allow applications to explicitly
manipulate the row state for DataSet and DataTable rows.

SetAdded method Changes the RowState(Gets the current state of the row with
regard to its relationship to the DataRowCollection) of DataRow to Added.

10. Namespace-Qualified Tables
A DataSet can now support tables that have the same Table
Name but with a different Namespace, providing a mechanism to
avoid naming conflicts.

DataTable.TableName Gets or sets the name of the
DataTable.

DataTable.NameSpace Gets or sets the namespace for the
XML representation of the data stored in the DataTable..

Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
contd
11. XML Data Type Support
XML data type is just like INT or VARCHAR, and SQL Server 2005 allows in-
place querying and processing of this data type using a series of XML-specific
functions.
There is also support for storing collections of XML schemas in the database,
enabling database-based schema validations.


12. Asynchronous Support
Asynchronous support lets client applications submit queries without blocking
the UI.
ADO.NET 2.0 lets server applications issue multiple database requests on
different threads.
The support works with SQL Server 2005, SQL Server 2000, and SQL Server
7.0.
Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
Contd..
13. Query Notification
If records in the underlying database table change, then your Web application
will display old, inaccurate data. ADO.Net 2.0 provides us with the feature where in
the cache can be invalidated and the data is re-loaded in the cache when the request
is made if the underlying data changes before the cache expires.

14. Connection Pooling
ADO.NET new pooling control for SQL and Oracle
ADO.NET 2.0 extends this
Can explicitly clear a pool SqlConnection.ClearPool
Or clear all pools SqlConnection.ClearPools
Not for ODBC or OLEDB

Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
LINQ on .NET
LINQ
is a querying concept that allows the developer to write SQL-like queries natively in
any chosen .NET programming language
LINQ comes in three sub-sets:
1.LINQ to objects, for querying any sequence of objects(LINQ)
2.LINQ to ADO.NET(DLINQ) for databases, which includes the following:
LINQ to Entities, for querying EDM(Entity Data Model) entities
LINQ to DataSet, for querying objects in the DataSet family
LINQ to SQL, for querying relational databases
3.LINQ to XML, for querying XML data (XLINQ)

Why LINQ:

Query Validation
Performance
Paging
DataSet
Utkata Soft Solutions Pvt Ltd Utkata Confidential Not For Distribution
Factors Affecting the Performance of ADO.Net

Inefficient queries
Retrieving too much data
Inefficient or missing indexes
Unnecessary round trips
Too many open connections
Failure to release resources
Transaction misuse

Potrebbero piacerti anche