Example: dental hygienist

Data Access with ADO - softwareresearch.net

data Access with Dr. Herbert Praehofer Institute for System Software Johannes Kepler University Linz Dr. Dietrich Birngruber Software Architect TechTalk University of Linz, Institute for System Software, 2004. published under the Microsoft Curriculum License Introduction Connection-oriented Access Connectionless Access Database Access with DataAdapter Integration with XML. Preview of Summary Is the .NET technology for accessing structured data Uniform object oriented interface for different data sources relational data bases XML data other data sources Designed for distributed and Web applications Provides 2 models for data Access connection-oriented connectionless 3.

Data Access with ADO.NET Dr. Herbert Praehofer Institute for System Software Johannes Kepler University Linz Dr. Dietrich Birngruber Software Architect

Tags:

  With, Data, Access, Softwareresearch, Data access with ado

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Data Access with ADO - softwareresearch.net

1 data Access with Dr. Herbert Praehofer Institute for System Software Johannes Kepler University Linz Dr. Dietrich Birngruber Software Architect TechTalk University of Linz, Institute for System Software, 2004. published under the Microsoft Curriculum License Introduction Connection-oriented Access Connectionless Access Database Access with DataAdapter Integration with XML. Preview of Summary Is the .NET technology for accessing structured data Uniform object oriented interface for different data sources relational data bases XML data other data sources Designed for distributed and Web applications Provides 2 models for data Access connection-oriented connectionless 3.

2 Idea of the Universal data Access Connection of (object-oriented) programming languages and relational data bases Uniform programming model and API. Special implementations for data sources (providers). MsSql API DB2. Application Oracle ODBC ? Provider 4. data Providers Microsoft's layered architecture for data Access SQL Server Oracle ODBC OLEDB. MySQL. SQL- data Non-SQL- data MS SQL Server, Oracle, Directory Services, Mail, Jet, Foxpro, .. Text, Video, .. 5. History of Universal data Access (Microsoft). ODBC.

3 OLE DB. ADO (Active data Objects). ADO connection-oriented connection-oriented +. connectionless sequential Access main-memory representation with direct Access only one table supported more than one table supported COM-marshalling XML-marshalling 6. Architecture of connectionless connection-oriented 7. Connection-oriented versus Connectionless Connection-oriented Keeps the connection to the data base alive Intended for applications with : short running transactions only a few parallel accesses up-to-date data Connectionless No permanent connection to the data source data cached in main memory Changes in main memory changes in data source Intended for applications with : many parallel and long lasting accesses ( : web applications).

4 8. Assembly and Namespaces Assembly Namespaces: general data types classes for implementing providers OLE DB provider Microsoft SQL Server provider data types for SQL Server ODBC provider (since .NET ). Oracle provider (since .NET ). Compact Framework 9. Introduction Connection-oriented Access Connectionless Access Database Access with DataAdapter Integration with XML. Preview of Summary Architecture DbConnection represents connection to the data source DbCommand represents a SQL command DbTransaction represents a transaction commands can be executed within a transaction DataReader result of a data base query allows sequential reading of rows 11.

5 Class Hierarchy General interface definitions IDbConnection IDbCommand IDbTransaction IDataReader Special implementations OleDb: implementation for OLEDB. Sql: implementation for SQL Server Oracle: implementation for Oracle Odbc: implementation for ODBC. SqlCe: implementation for SQL Server CE data base 12. Example: Northwind Database Microsoft Example for SQL Server Reading of the table Employees Output of EmployeesID, LastName, FirstName for all rows of table Employees Run 13. Program Pattern for Connection-oriented data Access 1.

6 Declare the connection try {. 1.) Request connection to database 2.) Execute SQL statements 3.) Process result 4.) Release Resources } catch ( Exception ) {. Handle exception } finally {. try {. 4.) Close connection } catch (Exception). { Handle exception }. }. 14. Example: EmployeeReader (1). using System;. using ;. using ;. public class EmployeeReader {. public static void Main() {. Establish connection string connStr = "provider=SQLOLEDB; data source=(local)\\NetSDK; " +. "initial catalog=Northwind; user id=sa; password=; ".}}

7 IDbConnection con = null; // declare connection object try {. con = new OleDbConnection(connStr); // create connection object (); // open connection Execute command //----- create SQL command IDbCommand cmd = ();. = "SELECT EmployeeID, LastName, FirstName FROM Employees";. //----- execute SQL command; result is an OleDbDataReader IDataReader reader = ();. // continue next page 15. Example: EmployeeReader (2). Read and process data rows IDataReader reader = ();. object[] dataRow = new object[ ];. while ( ()) {.}}

8 Int cols = (dataRow);. for (int i = 0; i < cols; i++) ("| {0} " , dataRow[i]);. ();. }. Close connection //----- close reader ();. } catch (Exception e) {. ( );. } finally {. try {. if (con != null). // ----- close connection ();. } catch (Exception ex) { ( ); }. }. }. } 16. Interface IDbConnection ConnectionString defines data base connection string ConnectionString {get; set;}. Open and close connection void Close();. void Open();. Properties of connection object string Database {get;}. int ConnectionTimeout {get;}.

9 ConnectionState State {get;}. Creates Command-Object IDbCommand CreateCommand();. Creates Transaction-Object IDbTransaction BeginTransaction();. IDbTransaction BeginTransaction(IsolationLevel lvl);. 17. IDbConnection: Property ConnectionString Key-value-pairs separated by semicolon (;). Configuration of the connection name of the provider identification of data source authentication of user other database-specific settings : OLEDB: "provider=SQLOLEDB; data source= \\NetSDK;. initial catalog=Northwind; user id=sa; password=; ".

10 "provider= ; data source=c:\bin\ ;". "provider=MSDAORA; data source=ORACLE8i7; user id=OLEDB; password=OLEDB;". : MS-SQL-Server: " data source=(local)\\NetSDK; initial catalog=Northwind; user id=sa;. pooling=false; Integrated Security=SSPI; connection timout=20;". 18. Command Objects * 1 *. IDbTransaction IDbCommand IDataParameter 1. IDbConnection Command objects define SQL statements or stored procedures Executed for a connection May have parameters May belong to a transaction 19. Interface IDbCommand CommandText defines SQL statement or stored procedure string CommandText {get; set;}.


Related search queries