.NET and DB2 united with IBM DB2.NET Data Provider Objectives :.NET ADO.NET DB2 and ADO.NET DB2 - ADO.NET applications

Similar documents
Create a Windows Application that Reads- Writes PI Data via PI OLEDB. Page 1

ADO.NET.NET Data Access and Manipulation Mechanism. Nikita Gandotra Assistant Professor, Department of Computer Science & IT

New programming language introduced by Microsoft contained in its.net technology Uses many of the best features of C++, Java, Visual Basic, and other

Mobile MOUSe ADO.NET FOR DEVELOPERS PART 1 ONLINE COURSE OUTLINE

BUILDING APPLICATIONS USING C# AND.NET FRAMEWORK (OBJECT-ORIENTED PROGRAMMING, X428.6)

An Introduction to ADO.Net

C# Syllabus. MS.NET Framework Introduction

Program Contents: DOTNET TRAINING IN CHENNAI

B Nagaraju

CMPT 354 Database Systems I

PLATFORM TECHNOLOGY UNIT-4

ADO.NET 2.0. database programming with

Mastering VB.NET using Visual Studio 2010 Course Length: 5 days Price: $2,500

.NET FRAMEWORK. Visual C#.Net

.Net Interview Questions

6 Microsoft.Data.Odbc

Saikat Banerjee Page 1

UNIT 1. Introduction to Microsoft.NET framework and Basics of VB.Net

S.Sakthi Vinayagam Sr. AP/CSE, C.Arun AP/IT

Contents. Chapter 1 Introducing ADO.NET...1. Acknowledgments...xiii. About the Authors...xv. Introduction...xix

It is the primary data access model for.net applications Next version of ADO Can be divided into two parts. Resides in System.

ASP.NET 2.0 p. 1.NET Framework 2.0 p. 2 ASP.NET 2.0 p. 4 New Features p. 5 Special Folders Make Integration Easier p. 5 Security p.

ASP.NET Web Forms Programming Using Visual Basic.NET

Building Datacentric Applications

DOT NET Syllabus (6 Months)

Developing an app using Web Services, DB2, and.net

ADO.NET for Beginners

Saikat Banerjee Page 1

SECURED PROGRAMMING IN.NET DETAILED TRAINING CONTENT INDUSTRIAL TRAINING PROGRAM ( )

iseries Access in the.net World

DB2 Development in.net Environment

All India Council For Technical Skill Development (AICTSD) In Association with IITians Embedded Technosolution

Introduction to.net Framework Week 1. Tahir Nawaz

Department of Computer Applications

Microsoft..NET Framework. Overview

Developing Microsoft.NET Applications for Windows (Visual Basic.NET)

PESIT- Bangalore South Campus Hosur Road (1km Before Electronic city) Bangalore

2. A GUI A. uses buttons, menus, and icons B. should be easy for a user to manipulate C. both (a) and (b) D. stands for Graphic Use Interaction

.NET Connector. (MS Windows)

Microsoft Visual Basic 2005: Reloaded

ADO.NET Overview. Connected Architecture. SqlConnection, SqlCommand, DataReader class. Disconnected Architecture

ADO.NET in Visual Basic

Dot Net Online Training

Introducing.NET Data Management

IBM DB2 9 Application Developer. Practice Test. Version 1.1.

Developing DB2 CLR Procedures in VS.NET

Developing DB2 CLR Procedures in VS.NET

.Net. Course Content ASP.NET

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 14 Database Connectivity and Web Technologies

Web Services in.net (2)

About the Authors Introduction p. 1 Exploring Application Architectures p. 9 Introduction p. 9 Choosing the "Right" Architecture p.

EVALUATION COPY. Unauthorized reproduction or distribution is prohibited. Table of Contents (Detailed)

C# is intended to be a simple, modern, general-purpose, objectoriented programming language. Its development team is led by Anders Hejlsberg.

Visual Basic.NET Complete Sybex, Inc.

C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies. Objectives (1 of 2)

This web service can be available to any user on the internet regardless of who developed it.

Oracle Rdb Technical Forums

A201 Object Oriented Programming with Visual Basic.Net

HCIM SUMMER WORKSHOP Introduction to C#

A Programmer s Guide to ADO.NET in C# MAHESH CHAND

Windows Database Applications

ALPHAPRIMETECH 112 New South Road, Hicksville, NY 11801

.NET 4.6 MICROSOFT CURRICULUM MICROSOFT.NET 2015 (4.6)

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

Microsoft.NET Programming (C#, ASP.NET,ADO.NET, VB.NET, Crystal Report, Sql Server) Goal: Make the learner proficient in the usage of MS Technologies

ASP.net. Microsoft. Getting Started with. protected void Page_Load(object sender, EventArgs e) { productsdatatable = new DataTable();

Introduction to.net. The path. The Distributed Group University of Seville Spain - España. Introduction The elements of.net. Assessments Conclusions

Unit 1: Visual Basic.NET and the.net Framework

Oracle is a registered trademark, and Oracle Rdb, Oracle RMU and Oracle SQL/Services are trademark or registered trademarks of Oracle Corporation.

A NET Refresher

Hands-On Lab. Introduction to SQL Azure. Lab version: Last updated: 12/15/2010

ADO.NET Using Visual Basic 2005 Table of Contents

Working with Data in ASP.NET 2.0 :: Using Existing Stored Procedures for the Typed DataSet s TableAdapters Introduction

AUTHENTICATED WEB MANAGEMENT SYSTEM

overview of, ASPNET User, Auto mode, 348 AutoIncrement property, 202 AutoNumber fields, 100 AVG function, 71

How to work with data sources and datasets

Integration Services. Creating an ETL Solution with SSIS. Module Overview. Introduction to ETL with SSIS Implementing Data Flow

Introduction to.net Framework

C# Programming Syllabus

Quick Start: Progress DataDirect Connect for ADO.NET Oracle ADO.NET Entity Framework Data Provider

M4.1-R4: APPLICATION OF.NET TECHNOLOGY

2310C VB - Developing Web Applications Using Microsoft Visual Studio 2008 Course Number: 2310C Course Length: 5 Days

Top 40.NET Interview Questions & Answers

Programming with ADO.NET

Implementation on Curriculum Management System based on.net Li Ma

.NET-6Weeks Project Based Training

Event-based Programming

Apex TG India Pvt. Ltd.

Visual Studio.NET for AutoCAD Programmers

How to use data sources with databases (part 1)

DOT NET SYLLABUS FOR 6 MONTHS

> ADO.NET: ActiveX Data Objects for.net, set of components used to interact with any DB/ XML docs

Microsoft ASP.NET Whole Course Syllabus upto Developer Module (Including all three module Primary.NET + Advance Course Techniques+ Developer Tricks)

Microsoft Visual C# 2005: Developing Applications Table of Contents

Mobile MOUSe ASP.NET FOR DEVELOPERS PART 1 ONLINE COURSE OUTLINE

INTERNAL ASSESSMENT TEST 1 ANSWER KEY

Lecture 10: Database. Lisa (Ling) Liu

TRANSACTION SERVICES ARE USUALLY THE MAIN reason why Enterprise Services

Mac Id Authentication for HR Employee Information

Integrating With.NET. Patterns for Leveraging SAS in Microsoft's Strategic Architecture. Dan Jahn SAS

Transcription:

.NET and DB2 united with IBM DB2.NET Data Provider Objectives :.NET ADO.NET DB2 and ADO.NET DB2 - ADO.NET applications ABIS Training & Consulting 1

DEMO Win Forms client application queries DB2 according to a parameterized query Result is displayed and changed by user Changes are executed in DB2 database.net and DB2 united with IBM DB2.NET Data Provider ABIS 2

The.NET Framework 1 Common Language Runtime (CLR) + Class Library Common Language Runtime 1.1 C++ C# VB C++ is compiled to IL IL IL runs in exe runs on / interpretes to Common Language Runtime IE IIS SQL Srv Windows.NET and DB2 united with IBM DB2.NET Data Provider ABIS 3

The.NET Framework: CLR 1. Compilation and Execution Model source code: VB, C#, C++, COBOL,... result of compilation: binary files containing an intermediate representation of the source constructs combination of metadata and Microsoft Intermediate Language (MSIL) In order for these binaries to be executed, the CLR must be present on the target machine execution: when these binaries are executed they cause the CLR to load the CLR then takes over and manages the execution JIT compilation (converting the MSIL as needed into the correct stream of instructions for the underlying processor).net and DB2 united with IBM DB2.NET Data Provider ABIS 4

The.NET Framework: CLR 2. The Common Type System (CTS) The CTS defines the rules by which all types are declared, defined and managed, regardless of source language. The CTS is designed to be rich and flexible enough to support a wide variety of source languages 3. The Common Language Specification (CLS) interacting with code that is written in a different programming language.net and DB2 united with IBM DB2.NET Data Provider ABIS 5

The.NET Framework: Class Library The Framework Class Library 1.2 Any programming language (conform to CLS) can use classes Class Library includes more than 3500 classes with support for: interaction with databases manipulating tabular and tree-structured data consuming and producing XML core functionality, such as interacting with base data types; console, network and file I/O, exceptions web-based (thin client) applications desktop-based (thick client) applications with broad support for the Windows GUI. SOAP-based XML web services..net and DB2 united with IBM DB2.NET Data Provider ABIS 6

The.NET Framework: Class Library 1. Namespace: a logical design-time naming convenience... using System.Windows.Forms; namespace WindowsApplication1 { public class Form1 : System.Windows.Forms.Form { private TextBox textbox1; private System.Windows.Forms.Button button1;... class library is comprised of namespaces each namespace contains types that you can use in your program using keyword (C#): to avoid fully qualified names (namespace.typename) Namespaces provide scope: Two classes with the same name can be used in your program as long as they are in different namespaces and as long as you qualify the names to the namespaces.net and DB2 united with IBM DB2.NET Data Provider ABIS 7

The.NET Framework: Class Library 2. Managed DLLs (=Assemblies) the class library is contained in multiple DLLs or assemblies types in namespaces reside in a managed DLL namespaces organize the objects defined in an assembly every type is loaded in the context of an assembly if a certain type is needed ---> add a reference to the DLL that contains that type.net and DB2 united with IBM DB2.NET Data Provider ABIS 8

ADO.NET 2 Data Providers 2.1 ADO.NET includes classes to access and work with data classes can be data source independent ex. DataSet is part of System.Data namespace is found in System.Data.dll classes can be data source dependent key objects: Connection Command DataReader DataAdapter ---> provided by a.net Data Provider ---> part of another namespace, other dll needed.net and DB2 united with IBM DB2.NET Data Provider ABIS 9

ADO.NET: Data Providers ADO.NET ships with a - OLE DB.NET Data Provider = provider for OLE DB data sources calls through the OLE DB layer - SQL Server.NET Data Provider communicates with native data transfer protocol of SQL Server Downloadable from Microsoft: ODBC.NET Data Provider,... You can write your own Data Provider for any source... native data providers replace the need of a OLE DB driver.net and DB2 united with IBM DB2.NET Data Provider ABIS 10

ADO.NET: Data Providers ADO.NET and the DB2.NET Data Provider ADO.NET Dataset OLEDB.NET DATAPROVIDER DB2.NET DATAPROVIDER OLEDBConnection OLEDBDataAdapter DB2DataAdapter DB2Connection OLEDB PROVIDER other DB DB2.NET and DB2 united with IBM DB2.NET Data Provider ABIS 11

ADO.NET: Architecture Architecture 2.2 no continuously live connections tight integration with XML DataSet: in-memory disconnected cache of data retrieved from a datasource ==> new application architecture: loosely coupled applications <---> data commands for direct database access transactions.net and DB2 united with IBM DB2.NET Data Provider ABIS 12

ADO.NET: Architecture.NET and DB2 united with IBM DB2.NET Data Provider ABIS 13

ADO.NET: DataSet DataSet 2.3 a cache of records retrieved from a datasource independent of datasource a relational view of data that can be represented in XML access and manipulate the data two ways: - as tables in a relational database one table or more tables, inclusive relationships between the tables constraints (unique constraints, FK constraints) - as XML data is transferred and persisted as XML DataSet is defined with XML schema (typed DataSet) no current record, all records are available changes to DataSet can be written back to data source diffgram.net and DB2 united with IBM DB2.NET Data Provider ABIS 14

DB2 & ADO.NET 3 IBM DB2.NET enablement 3.1 DB2 development add-ins for Visual studio data provider.net and DB2 united with IBM DB2.NET Data Provider ABIS 15

DB2 & ADO.NET: IBM data provider DB2.NET data provider 3.2.NET applications can access - DB2 Universal Database for LUW Version 8 - DB2 Universal Database for OS/390 and z/os Version 6 and Version 7 via DB2 Connect reference to assembly: IBM.Data.DB2.dll namespace: IBM.Data.DB2 Some important classes: DB2DataAdapter DB2Command DB2Connection DB2DataReader....NET and DB2 united with IBM DB2.NET Data Provider ABIS 16

DB2 & ADO.NET: Visual studio add-ins Visual studio add-ins 3.3.NET and DB2 united with IBM DB2.NET Data Provider ABIS 17

DB2 & ADO.NET: Visual studio add-ins - IBM Explorer - DB2 Tools toolbar - DB2 Database Project - DB2 SQL Editor - Integrated help - Adapted Toolbox - IBM DB2 output message pane - DB2 Data Adapter Configuration Wizard - generate DB2 ADO.NET data components by drag and drop - browse metadata of DB2 objects in VS properties browser requirements: Visual Studio.NET 2002 + DB2 Application Development client V8.1.2.NET 2003 ----> DB2: service pack 3 or higher.net and DB2 united with IBM DB2.NET Data Provider ABIS 18

DB2 ADO.NET Applications 4 Where is my cursor? 4.1 there are no updateable server-side cursors - DB2DataReader: forward-only, read-only, server side cursor - DataSet: disconnected client cursor + DB2DataAdapter.NET and DB2 united with IBM DB2.NET Data Provider ABIS 19

DB2 ADO.NET Applications: DataSet and DB2DataAdapter Working with a DataSet and DB2DataAdapter 4.2 DB2DataAdapter: - is used to exchange data between a DataSet and a DB2 table. - represents a set of data commands and a connection to a database - DataSet / DB2DataAdapters: one to many. Each DataAdapter can be used for one or more DataTable objects.net and DB2 united with IBM DB2.NET Data Provider ABIS 20

DB2 ADO.NET Applications: DataSet and DB2DataAdapter Fill method: - loads data into the DataSet by executing a DB2SelectCommand App DB2DataSet1 DB2DataAdapter DB2Command DB2Connection EnforceConstraints DeleteCommand UpdateCommand SelectCommand InsertCommand CommandText Connection ConnectionString Clear() AcceptChanges() ReadXML() WriteXML() Fill(DataSet) Update(DataSet) ExecuteNonQuery() ExecuteReader() :DataReader Open() Close() DataReader.NET and DB2 united with IBM DB2.NET Data Provider ABIS 21

DB2 ADO.NET Applications: DataSet and DB2DataAdapter private IBM.Data.DB2.DB2Command db2selectcommand1; private IBM.Data.DB2.DB2DataAdapter db2dataadapter1; private WindowsApplication2.DB2DataSet1 db2dataset11; private IBM.Data.DB2.DB2Connection db2connection1;... this.db2selectcommand1 = new IBM.Data.DB2.DB2Command(); this.db2connection1 = new IBM.Data.DB2.DB2Connection(); this.db2dataadapter1 = new IBM.Data.DB2.DB2DataAdapter(); this.db2dataset11 = new WindowsApplication2.DB2DataSet1(); this.button1.click += new System.EventHandler(this.button1_Click); this.db2dataadapter1.selectcommand = this.db2selectcommand1; this.db2selectcommand1.commandtext = "SELECT \"CONO\", \"CONAME\",... FROM \"DB2ADMIN\".\"TUTCOMPANIES\" this.db2selectcommand1.connection = this.db2connection1; private void button1_click(object sender, System.EventArgs e) { db2dataadapter1.fill(db2dataset11); }.NET and DB2 united with IBM DB2.NET Data Provider ABIS 22

DB2 ADO.NET Applications: DataSet and DB2DataAdapter Update method: sends changes back to the database by executing DB2InsertCommand, DB2UpdateCommand and DB2deleteCommand... this.db2dataadapter1.updatecommand = this.db2updatecommand1; this.db2dataadapter1.insertcommand = this.db2insertcommand1; this.db2dataadapter1.deletecommand = this.db2deletecommand1; this.db2updatecommand1.commandtext =... this.db2insertcommand1.commandtext =... this.db2deletecommand1.commandtext =... this.db2updatecommand1.connection = this.db2connection1; this.db2insertcommand1.connection = this.db2connection1; this.db2deletecommand1.connection = this.db2connection1; private void button1_click(object sender, System.EventArgs e) { db2dataadapter1.update(db2dataset11); }.NET and DB2 united with IBM DB2.NET Data Provider ABIS 23

DB2 ADO.NET Applications: DataSet and DB2DataAdapter Remarks: - updates to the datasource are performed in a certain order updates and inserts of PK updating child - parent tables autoincrement columns exceptions - 1 sql-statement = 1 transaction stops executing when error is encountered constraint, null, datatype exceptions solved in DataSet but DataSet contains only part of table - meanwhile an update can be performed at the datasource optimistic concurrency.net and DB2 united with IBM DB2.NET Data Provider ABIS 24

DB2 ADO.NET Applications: DataSet and transactions DataSets and transactions 4.3 1. Working with transactions - You must explicitly open en close the connection App DB2Connection DB2Transaction DB2Command ConnectionString <<create>> Connection IsolationLevel * CommandText Connection Transaction Open() Close() BeginTransaction() :Transaction Commit() Rollback() * ExecuteNonQuery().NET and DB2 united with IBM DB2.NET Data Provider ABIS 25

DB2 ADO.NET Applications: DataSet and transactions private IBM.Data.DB2.DB2Transaction db2transaction1;... private void button2_click(object sender, System.EventArgs e) { try { db2connection1.open(); db2transaction1 = db2connection1.begintransaction(); db2updatecommand1.transaction = db2transaction1; db2insertcommand1.transaction = db2transaction1; db2deletecommand1.transaction = db2transaction1; db2dataadapter1.update(db2dataset11); db2transaction1.commit(); db2connection1.close(); } catch (IBM.Data.DB2.DB2Exception exep) { MessageBox.Show(exep.Message, exep.gettype().tostring()); db2transaction1.rollback(); db2dataadapter1.fill(db2dataset11); db2connection1.close(); } }.NET and DB2 united with IBM DB2.NET Data Provider ABIS 26

DB2 ADO.NET Applications: DataSet and transactions 2. Working without transactions idea: skip update that generates the error notify user continue with next rows this.db2dataadapter1.continueupdateonerror = true; this.db2dataadapter1.rowupdated += new IBM.Data.DB2.DB2RowUpdatedEventHandler(this.db2DataAdapter1_RowUpdated); private void db2dataadapter1_rowupdated(object sender, IBM.Data.DB2.DB2RowUpdatedEventArgs e) { //if (e.status == UpdateStatus.ErrorsOccurred) if (e.recordsaffected == 0) { e.row.rowerror = "Fout"; MessageBox.Show("in RowUpdatedevent : " + e.errors.tostring()); } }.NET and DB2 united with IBM DB2.NET Data Provider ABIS 27

DB2 ADO.NET Applications: DataSet and transactions this.db2dataadapter1.rowupdated += new IBM.Data.DB2.DB2RowUpdatedEventHandler(this.db2DataAdapter1_RowUpdated); private void db2dataadapter1_rowupdated(object sender, IBM.Data.DB2.DB2RowUpdatedEventArgs e) { if (e.recordsaffected == 0) { e.row.rowerror = "Fout"; e.status = UpdateStatus.SkipCurrentRow MessageBox.Show("in RowUpdatedevent : " + e.errors.tostring()); } }.NET and DB2 united with IBM DB2.NET Data Provider ABIS 28

DB2 ADO.NET Applications: DataSet and transactions 3. Isolation levels:.net ReadCommitted ReadUncommitted RepeatableRead Serializable DB2 Cursor Stability (default) Uncommitted Read Read Stability Repeatable Read db2transaction1 = db2connection1.begintransaction(isolationlevel.readcommitted); Remark: The DataSet has its own API, for example: it s possible to execute updates,..., commit changes on the DataSet itself.net and DB2 united with IBM DB2.NET Data Provider ABIS 29

DB2 ADO.NET Applications: Optimistic Concurrency Optimistic Concurrency 4.4 Generated update statement: UPDATE "DB2ADMIN"."TUTCOMPANIES" SET "CONO" =?, "CONAME" =?, "COSTREET" =?, "COSTRNO" =?,... WHERE ("CONO" =?) AND ("CONAME" =? OR CAST(? as CHARACTER(45)) IS NULL AND "CONAME" IS NULL)AND ("COSTREET" =?) AND ("COSTRNO" =? OR CAST(? as VARCHAR(10)) IS NULL AND "COSTRNO" IS NULL) AND ("COTOWN" =? OR CAST(? as CHARACTER(45)) IS NULL AND "COTOWN" IS NULL)... two techniques: DBConcurrencyException: The exception that is thrown by the DataAdapter during the update operation if the number of rows affected equals zero. or Rowupdated event.net and DB2 united with IBM DB2.NET Data Provider ABIS 30

DB2 ADO.NET Applications: Optimistic Concurrency private void button2_click(object sender, System.EventArgs e) { try { db2dataadapter1.update(db2dataset11); } catch (DBConcurrencyException exep) { MessageBox.Show("foutDBconcurrencyException"); } }.NET and DB2 united with IBM DB2.NET Data Provider ABIS 31

DB2 ADO.NET Applications: DB2CommandBuilder DB2CommandBuilder 4.5 Automatically generates single-table commands uses the SelectCommand property to retrieve a required set of metadata The DB2CommandBuilder also uses the Connection, CommandTimeout, and Transaction properties referenced by the SelectCommand ÿ private IBM.Data.DB2.DB2CommandBuilder db2commandbuilder1;... this.db2dataadapter1.selectcommand = this.db2selectcommand1; this.db2commandbuilder1 = new IBM.Data.DB2.DB2CommandBuilder(); this.db2commandbuilder1.dataadapter = this.db2dataadapter1;.net and DB2 united with IBM DB2.NET Data Provider ABIS 32

DB2 ADO.NET Applications: DB2CommandBuilder Trace output: - dynamic prepare select command - call SYSIBM.SQLPRIMARYKEYS - generated update statement UPDATE "DB2ADMIN"."TUTCOMPANIES" SET "CONAME" =? WHERE ("CONO" =?) AND ("CONAME" =? OR CAST(? as CHARACTER(45)) IS NULL AND "CONAME" IS NULL)AND ("COSTREET" =?) AND ("COSTRNO" =? OR CAST(? as VARCHAR(10)) IS NULL AND "COSTRNO" IS NULL) AND ("COTOWN" =? OR CAST(? as CHARACTER(45)) IS NULL AND "COTOWN" IS NULL)....NET and DB2 united with IBM DB2.NET Data Provider ABIS 33

Questions? kplatteborze@abis.be.net and DB2 united with IBM DB2.NET Data Provider ABIS 34