Presentation is loading. Please wait.

Presentation is loading. Please wait.

ADO.NET: Working in Disconnected Environment Sergey Baidachni MCT, MCSD, MCDBA.

Similar presentations


Presentation on theme: "ADO.NET: Working in Disconnected Environment Sergey Baidachni MCT, MCSD, MCDBA."— Presentation transcript:

1 ADO.NET: Working in Disconnected Environment Sergey Baidachni MCT, MCSD, MCDBA

2 Overview Introduction Architecture of ADO.NET ObjectSpaces – New technologies

3 Introduction Data Storage Connected environment Disconnected environment ADO.NET vs. ADO Demonstration (ADO.NET and Excel)

4 Data Storage ADO.NET Relational Database Data storage - method of storing specific items that together constitute a unit of information. Hierarchical SQL ServerOracle Access XML StructuredUnstructured Excel Active Directory CSV

5 Connected Environment (Scenario) 1. Open connection 2. Execute command 3. Process rows in reader 4. Close reader 5. Close connection

6 Connected Environment Working with data directly via open connection Advantages  Simple security realization  Work with real data  Simple organization of distributed work Drawbacks  Continual connection  Not available via Internet

7 Disconnected Environment (Scenarion) 1. Open connection 2. Fill the DataSet 3. Close connection 4. Process the DataSet 5. Open connection 6. Update the data source 7. Close connection

8 Disconnected Environment Storage of data local copy from repository Possibility to update the main data source Advantages  Economy of server resources  Does not require continual connection Drawbacks  Demands conflict resolution while data update  Data is not always up to date

9 ADO.NET vs. ADO ADO Connection Command RecordSet ADO.NET XxxConnection XxxTransaction XxxCommand XxxDataReader XxxDataAdapter DataSet

10 Demonstration OleDbConnection conn=new OleDbConnection(); OleDbCommand comm=new OleDbCommand(); OleDbDataAdapter adapt=new OleDbDataAdapter(comm); DataSet data=new DataSet(); conn.ConnectionString= “Provider=Microsoft.Jet.OLEDB.4.0; c:\myexcel.xls;Extended Properties=""Excel 8.0;HDR=NO""“; comm.Connection=conn; comm.CommandText=“select * from [Sheet1$]”; adapt.Fill(data);

11 Architecture of ADO.NET Data providers What does it look like? Connection to the source Command creation Cursors Data storage in memory DataAdapter – automatic data upload XML Integration

12 .NET Data Providers Concept of data provider Provider types  SQL.NET Data Provider  Oracle.NET Data Provider  OleDB.NET Data Provider  Odbc.NET Data Provider How to select data provider

13 Как это выглядит.NET Data Provider Connection Command DataReader DataAdapter DataSet DataTable DataRelation DataColumn DataRow DataConstraint SelectCommand InsertCommand DeleteCommand UpdateCommand

14 Connection What is Connection? Define Connection  SqlConnection conn=new SqlConnection();  Conn.ConnectionString=“User ID=sa;password=; Data Source=MyServer;Initial Catalog=Northwind;” ConnectionString Parameters  Provider  Data Source  Initial Catalog  Integrated Security  UserID/Password

15 Connection (Error and Pooling) System.Data.SqlClient.SqlException Errors collection SqlError  Class  LineNumber  Message  Number Pooling and Dispose method

16 Command Object A command object is a reference to a SQL statement or stored procedure Properties  Connection  CommandType  CommandText  Parameters Methods  ExecuteNonQuery  ExecuteReader  ExecuteScalar

17 DataReader Object What is query? Forward-only cursor Read method  Read next record  Return true if record is exist IsDbNull Close method NextResult – for multiply select statements

18 What Are DataSets and DataTables ServerData Store Database Connection Stored Procedure DataSet DataTable

19 The DataSet Object Model Common collections  Tables (collection of DataTable objects)  Relations (collection of DataRelation objects) Data binding to Web and Windows controls supported Schema can be defined programmatically or using XSD DataRow DataColumn DataTable DataRelation Constraints

20 What Is a DataAdapter? Data source DataAdapter DataTable DataSet DataAdapter Fill Update Fill Update

21 The XxxDataAdapter Object Model sp_SELECT XxxCommand SelectCommandUpdateCommandInsertCommandDeleteCommand XxxDataAdapter XxxCommand XxxConnection sp_UPDATEsp_INSERTsp_DELETE XxxDataReader

22 Demo

23 XML Support ADO.NET is tightly integrated with XML Using XML in a disconnected application XML Web Services DataSet Request data11 SQL query22 Results33 XML 44 Updated XML 55 SQL updates66 Data SourceClient DataSet

24 Object Spaces Introduction to problem What is Object Spaces? What do we need? How can we resolve the problem

25 Introduction to Problem There’s something apparently missing Current situation Database public struct Customer { int customerID; string customerName; } ….. Customer LoadCustomer(int id){…} void SaveCustomer(Customer obj){…}

26 What is Object Spaces? Relation between object and database Way to avoid long-drawn coding ObjectSpace Database Map Files

27 What do we need? Single table to single Object Object hierarchy to many tables Object hierarchy to single table Single Object to multiple tables Inheritance  All types in single table  Table for base type and related table per derived type

28 How we can resolve problem XML Again! RSD – Relational Schema Definition OSD – Object Schema Definition MSD – Mapping Schema definition MappingSchema class

29 RSD Tables, fields and relations descriptions

30 OSD Objects description

31 MSD Mapping Schemes

32 ObjectSpace methods BeginTransaction Commit Rollback GetObject GetObjectReader GetObjectSet MarkForDeletion PersistChanges Resync StartTracking

33 msdn.microsoft.com/library


Download ppt "ADO.NET: Working in Disconnected Environment Sergey Baidachni MCT, MCSD, MCDBA."

Similar presentations


Ads by Google