Presentation is loading. Please wait.

Presentation is loading. Please wait.

Why ADO.NET Not your father’s Data Access.

Similar presentations


Presentation on theme: "Why ADO.NET Not your father’s Data Access."— Presentation transcript:

1 http://adoguy.com Why ADO.NET Not your father’s Data Access

2 http://adoguy.com Who I am Shawn Wildermuth Shawn Wildermuth swildermuth@adoguy.com swildermuth@adoguy.com swildermuth@adoguy.com Author of “Pragmatic ADO.NET” for Addison-Wesley Author of “Pragmatic ADO.NET” for Addison-Wesley For More Info: http://www.adoguy.com For More Info: http://www.adoguy.com

3 http://adoguy.com Short History of Data Access VT Objects VT Objects Data Access Objects (DAO/Jet) Data Access Objects (DAO/Jet) Open Database Connectivity (ODBC) Open Database Connectivity (ODBC) OLE for Databases (OLE/DB) OLE for Databases (OLE/DB) ActiveX Data Objects (ADO) ActiveX Data Objects (ADO)

4 http://adoguy.com Why is ADO.NET Better? Disconnected by Design Disconnected by Design Relational by Nature Relational by Nature Integration with XML Integration with XML Framework Supports Real Database Schema Framework Supports Real Database Schema

5 http://adoguy.com Connected vs. Disconnected “The Pizza Delivery Guy” “The Pizza Delivery Guy” Connections are expensive Connections are expensive Keeping connections alive longer than necessary is extremely wasteful Keeping connections alive longer than necessary is extremely wasteful Long lived connections impede load balancing Long lived connections impede load balancing Connections unnecessary while manipulating database results Connections unnecessary while manipulating database results

6 http://adoguy.com Introducing ADO.NET Managed Providers Managed Providers DataSet DataSet DataBinding in ASP.NET DataBinding in ASP.NET DataBinding in WinForms DataBinding in WinForms

7 http://adoguy.com Managed Providers ADO.NET’s Version of Providers (ADO, OLE/DB) and Drivers (ODBC) ADO.NET’s Version of Providers (ADO, OLE/DB) and Drivers (ODBC) Not the only way to access data in.NET (most notably the Xml classes) Not the only way to access data in.NET (most notably the Xml classes) Made up of a number of managed classes that implement known interfaces Made up of a number of managed classes that implement known interfaces

8 http://adoguy.com System.Data Namespace Dataset etc. DataRow DataColumn Data Relation ForeignKeyConstraintDataTable System.Data.Common Namespace etc. IDbCommand IDbDataReader IDbConnection Your Provider YourCommand YourConnection YourDataReader etc. System.Data.OleDb Namespace OleDbCommand OleDbConnection OleDbDataReader etc. System.Data.SqlClient Namespace SqlCommand SqlConnection SqlDataReader etc.

9 http://adoguy.com Managed Provider Abstraction System.Data DataSet System.Data.SqlClient SqlConnection SqlErrors SqlDataAdapter SqlDataReaderSqlCommand SqlParameter SqlParameters SqlError

10 http://adoguy.com Imports System Imports System.Data Imports System.Data.OleDb Module HelloADONET Sub Main() End Sub End Module Dim conn as OleDbConnection conn = new OleDbConnection("...") conn.Open() Dim cmd as OleDbCommand = conn.CreateCommand() cmd.CommandText = "SELECT * FROM AUTHORS" Dim rdr as OleDbDataReader = cmd.ExecuteReader() while rdr.Read() = true Console.WriteLine(rdr("au_id“)) End While conn.Close();

11 http://adoguy.com What are DataSets? Disconnected set of Database Data? Disconnected set of Database Data? In-Memory Database (IMDB)? In-Memory Database (IMDB)? A complex, relational data structure with built-in support for XML serialization? A complex, relational data structure with built-in support for XML serialization? All three? All three?

12 http://adoguy.com The DataSet DataSet Tables DataTable Rows DataRow

13 http://adoguy.com Imports System Imports System.Data Imports System.Data.SqlClient Module HelloADONET Sub Main() End Sub End Module Dim conn As SqlConnection = New SqlConnection("...") Dim da As SqlDataAdapter = New SqlDataAdapter() da.SelectCommand = conn.CreateCommand() da.SelectCommand.CommandText = "SELECT * FROM AUTHORS" Dim dataSet as DataSet = new DataSet() da.Fill(dataSet)

14 http://adoguy.com Typed DataSets Strong Typing Strong Typing XSD Based Schema XSD Based Schema Simple to Setup relationships, constraints, etc. Simple to Setup relationships, constraints, etc. Not very much use if you have amorphous data Not very much use if you have amorphous data

15 http://adoguy.com Using DataSets Bulk Data Loading is supported Bulk Data Loading is supported Two possible versions of all data, RowState.Original and RowState.Modified Two possible versions of all data, RowState.Original and RowState.Modified Relationship Navigation Relationship Navigation DataViews DataViews

16 http://adoguy.com The Hard Part Disconnected Concurrency Disconnected Concurrency –Optimistic Concurrency Supported by CommandBuilders –Optimistic Concurrency could be more efficient –Pessimistic Concurrency can be achieved with Check-out, Check-in

17 http://adoguy.com DataBinding in ASP.NET DataReaders do not bind DataReaders do not bind To bind to controls: To bind to controls: –Set DataSource –Set DataMember –Set DataTextField and DataValueField –Set DataTextFormat optionally –Call DataBind()

18 http://adoguy.com DataBinding in WinForms DataSource and DataMember key to binding DataSource and DataMember key to binding Master-Detail Binding Master-Detail Binding –Set multiple object to same DataSource –Set DataMember to name of Relationship –Use CurrencyManager to move the cursor if you do not want to use the master control

19 http://adoguy.com XML Integration DataSets XML Serialization DataSets XML Serialization –You can control the Serialization –Full XSD Support –Supports DiffGrams XmlDataDocument to Synchonize XML and DataSets XmlDataDocument to Synchonize XML and DataSets Commands and XmlReader Commands and XmlReader

20 http://adoguy.com Official Asides Batch Queries are cool! Batch Queries are cool! Caveats for SqlClient’s Connection Pooling Caveats for SqlClient’s Connection Pooling Trust your DBAs and strive to be like them : ) Trust your DBAs and strive to be like them : )

21 http://adoguy.com Questions?


Download ppt "Why ADO.NET Not your father’s Data Access."

Similar presentations


Ads by Google