Thông tin tài liệu
this print for content only—size & color not accurate 7.5 x 9.25 spine = x.xxx" xxx page count
Zehoo
for Oracle Database 11g
ODP .NET
The eXPeRT’s VOIce
®
In ORAcLe
Pro
ODP .NET for
Oracle Database 11g
cYAn
MAGenTA
YeLLOW
BLAcK
PAnTOne 123 c
Edmund Zehoo
Companion
eBook Available
Everything you need to work with Oracle
Database from Microsoft .NET
BOOKs fOR PROfessIOnALs BY PROfessIOnALs
®
Pro ODP .NET for Oracle Database 11g
Dear Reader,
Oracle Data Provider (ODP.NET) is a managed provider from Oracle enabling
.NET programmers to access the full feature set of the Oracle database with
speed and efficiency. Beginning with .NET 4.0, Microsoft’s own access provider
for Oracle is deprecated, making ODP.NET the clear choice for access to Oracle
from. Microsoft NET.
My goal in this book is to help you master ODP.NET by breaking the topic
into three easily digestible parts. First I explain how ODP.NET is different from
other providers and why you should use it. I walk you gently through the basics
of ODP.NET via digestible code snippets that you can quickly understand and test.
Next you’ll learn how you can tap powerful features of the Oracle database such
as Advanced Queuing, XML and UDT manipulation, globalization, distributed
transactions, and more. I show how to use these features, and how to use them
efficiently and securely. You will learn how to write lean, performance-optimized
code at every level of the data access stack.
Finally, I introduce the Oracle Developer Tools (ODT.NET) suite. ODT.NET inte-
grates seamlessly with Visual Studio to make writing and debugging easy. You’ll
even learn to generate ODP.NET applications on the fly.
I’ve had a lot of fun writing this book, and in the process I’ve re-explored and
renewed my love for a great product. If you are a .NET developer wanting to write
blazing-fast, Oracle Database applications, ODP.NET is a tool you must famil-
iarize yourself with. It is simply the fastest and most powerful way to access the
Oracle database from the .NET platform. My goal in this book is to have you wield
ODP.NET efficiently and confidently in your .NET projects. I wish you a great
journey and a fun read ahead.
Sincerely,
Edmund Zehoo
US $59.99
Shelve in:
Databases / Oracle
User level:
Intermediate–Advanced
Edmund Zehoo
THE APRESS ROADMAP
Applied Mathematics
For
Database Professionals
Pro ODP.NET for
Oracle Database 11g
Oracle
SQL Recipes
Troubleshooting
Oracle
Performance
Beginning
Oracle SQL
Beginning
Database Design
www.apress.com
SOURCE CODE ONLINE
Companion eBook
See last page for details
on $10 eBook version
ISBN 978-1-4302-2820-2
9 781430 228202
5 59 9 9
Pro
www.it-ebooks.info
www.it-ebooks.info
Pro ODP .NET for Oracle
Database 11g
Edmund Zehoo
www.it-ebooks.info
Pro ODP .NET for Oracle Database 11g
Copyright © 2010 by Edmund Zehoo
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-4302-2820-2
ISBN-13 (electronic): 978-1-4302-2821-9
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of
a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
President and Publisher: Paul Manning
Lead Editor: Jonathan Gennick
Technical Reviewer: Stephanie Lim
Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan
Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper,
Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom
Welsh
Coordinating Editor: Anita Castro
Copy Editor: Heather Lang
Compositor: Bytheway Publishing Services
Indexer: Toma Mulligan
Artist: April Milne
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or
visit www.springeronline.com.
For information on translations, please e-mail rights@apress.com, or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use.
eBook versions and licenses are also available for most titles. For more information, reference our Special
Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales.
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to
any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly
by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com. You will need to answer
questions pertaining to this book in order to successfully download the code.
www.it-ebooks.info
To my family,
for you are truly all I have.
www.it-ebooks.info
CONTENTS
Contents at a Glance
Contents at a Glance iv
Contents v
About the Author xvii
About the Technical Reviewer xviii
Acknowledgments xix
Chapter 1: Introduction to Oracle .NET Connectivity 1
Chapter 2: ODP.NET: A Functional Overview 19
Chapter 3: Connecting to Oracle with ODP.NET 49
Chapter 4: Retrieving and Manipulating Data with ODP.NET 69
Chapter 5: Using PL/SQL and .NET CLR Stored Procedures with ODP.NET 117
Chapter 6: ODP.NET Globalization 161
Chapter 7: Transactions with ODP.NET 187
Chapter 8: Oracle Database Change Notifications with ODP.NET 205
Chapter 9: Using Oracle Database Streams Advanced Queuing with ODP.NET 223
Chapter 10: Oracle XML Support 253
Chapter 11: ODP.NET Security Features 287
Chapter 12: ODP.NET Performance 317
Chapter 13: Design Patterns and Considerations in Using ODP.NET 351
Chapter 14: ODT.NET Tool Basics 373
Chapter 15: Building Data-Driven Applications with ODT.NET 401
Index 429
iv
www.it-ebooks.info
Contents
Contents at a Glance iv
Contents v
About the Author xvii
About the Technical Reviewer xviii
Acknowledgments xix
Chapter 1: Introduction to Oracle .NET Connectivity 1
Making the Transition from SQL Server to Oracle 2
Introducing Oracle Connectivity 3
Accessing Oracle from Unmanaged Code 4
Using OLEDB in Unmanaged Code 5
Oracle Provider for OLEDB 5
MS OLEDB Provider for Oracle 6
Using ODBC in Unmanaged Code 6
Oracle ODBC Driver 6
Microsoft ODBC for Oracle 7
Using OO4O in Unmanaged Code 7
Accessing Oracle from Managed Code 8
Using OLEDB.NET in Managed Code 8
Using ODBC.NET in Managed Code 9
Using the Microsoft .NET Managed Provider for Oracle 11
Introducing ODP.NET 11
Understanding the ODP.NET Architecture 12
v
www.it-ebooks.info
CONTENTS
Understanding the ODP.NET Classes 12
Accessing Data using ODP.NET 13
Using ODP.NET in ASP.NET Projects 13
Considering ODP.NET Performance 15
Introducing the Oracle Suite of Products 15
Summary 17
Chapter 2: ODP.NET: A Functional Overview 19
Exploring Oracle Features Accessible in ODP.NET Version 9 19
Manipulating XML 20
Manipulating LOBs 20
Using PL/SQL Associative Array Binding 21
Supporting Active Data Objects (ADO.NET) 2.0 22
Accessing Oracle Features from ODP.NET Version 10 22
Supporting Oracle Grids 23
Supporting Multiple Oracle Homes 23
Using Floating Point Data Types 24
Using Statement Caching 24
Supporting Command Cancellation and Timeout 25
Retrieving Parameters Programmatically 26
Supporting .NET Stored Procedures 26
Using Client Identifiers 26
Using Database Change Notifications 27
Managing Connection Pools 28
Optimizing Connection Pools for RAC 28
Using a REF Cursor as an IN/OUT Parameter 29
Using 64-bit ODP.NET 29
Controlling the FetchSize Property 29
Configuring ODP.NET 30
vi
www.it-ebooks.info
CONTENTS
Accessing Oracle Features from ODP.NET Version 11 30
Enhancing Performance 31
Deploying ODP.NET Using xcopy 31
Supporting Oracle User Defined Types (UDTs) 31
Performing Bulk Copy Operations 32
Using Windows Authenticated User Connections Pooling 32
Publishing Connection Pool Performance Counters 33
Supporting Self-Tuning for Applications 34
Using Oracle Streaming AQ 34
Supporting Promotable Local Transactions 35
Using ODP.NET Security Enhancements 37
Running Callbacks for HA Event Notifications 38
Starting Up and Shutting Down Databases 38
Getting Started 39
Installing Oracle Database 11g 39
Installing ODAC.NET 43
Summary 48
Chapter 3: Connecting to Oracle with ODP.NET 49
Connecting via TNS 49
Understanding the TNSNames.ora file 51
Connecting in Other Ways 52
Connecting Without TNSNames.ora 52
Connecting via EZConnect 53
Learning the ODP.NET Connection Parameters 54
Connecting with Connection Pooling Activated 54
Connecting via Integrated Windows Authentication 57
Connecting with Special Privileges 58
Using Other Connection String Attributes 59
vii
www.it-ebooks.info
CONTENTS
Checking Whether ODP.NET Is Installed 60
Dynamically Building an ODP.NET Connection String 61
Using the OracleConnectionStringBuilder Class 61
Retrieving Available Oracle Data Sources 62
Understanding Transparent Application Failover 62
Enabling TAF in Your Application 63
Using TAF Callbacks 65
Summary 67
Chapter 4: Retrieving and Manipulating Data with ODP.NET 69
Understanding ODP.NET Data Types 69
Creating a Sample Table 73
Retrieving Multiple Rows of Data 76
Retrieving a Single Value 78
Handling NULL Values in ODP.NET 79
Retrieving Data into a Dataset 80
Using Parameterized Queries 81
Updating Data 83
Executing a Single INSERT, UPDATE, or DELETE Statement 84
Committing Dataset Changes to the Database 85
Generating Command Objects 88
Handling Master-Detail Relationships 90
Creating a Second Table 90
Retrieving from Multiple Tables 91
Binding a .NET Form to Your Dataset 92
Committing Changes to Multiple Tables 94
Defining Table Relationships and Constraints in a DataSet 95
Manipulating LOBs and BFILEs 97
viii
www.it-ebooks.info
[...]... even nondatabase data sources as long as an OLEDB provider is written for it An example of this is the Microsoft Jet OLEDB provider, which is able to retrieve and store data from a Microsoft Excel file using OLEDB Oracle Provider for OLEDB The Oracle Provider for OLEDB (OraOLEDB) is Oracle s de facto standard OLEDB provider for the Oracle database Compared to the Microsoft OLEDB provider for Oracle. .. ODBC for Oracle Microsoft ODBC for Oracle is an ODBC implementation for access to Oracle databases Like the Microsoft OLE DB provider for Oracle, it only supports Oracle database versions up to 7x, with limited support for Oracle 8x It uses a connection string that looks like the following sample: Driver={Microsoft ODBC for Oracle} ;Server=TEST;Uid=edzehoo;Pwd=admin123; Note Microsoft ODBC for Oracle. .. flat file The latest release of ODP.NET features a suite of ASP.NET providers specifically created for the Oracle database, collectively referred to as the Oracle Providers for ASP.NET Table 1-3 lists the various ASP.NET providers and describes what they do Table 1-3 The Oracle Providers for ASP.NET Provider Name Description Oracle Membership This membership provider provides functionality to manage... CHAPTER 1 INTRODUCTION TO ORACLE NET CONNECTIVITY Using the Microsoft NET Managed Provider for Oracle The Microsoft.NET Managed Provider for Oracle is a provider built by Microsoft on top of the OCI API It sits in the call stack as shown in Figure 1-4 It is the closest equivalent to Oracle s ODP.NET provider Figure 1-4 Architectural overview of the Microsoft NET Managed Provider for Oracle Note The Microsoft... NET Managed Provider for Oracle as of June 2009 The provider will still be available in NET Framework 4 to support backward compatibility but will be labeled as deprecated Introducing ODP.NET The Oracle Data Provider for NET (ODP.NET) developed by Oracle is the preferred way to connect to an Oracle database from managed code It works with ADO.NET to provide fast and efficient access to the database Among... the consumer There are numerous OLEDB providers out there; typically, most databases would have an OLEDB driver written specifically for it so that developers can gain access to them For instance, Oracle provides the Oracle provider for OLEDB driver to access Oracle databases, and Microsoft provides the Microsoft SQL Server provider to access Microsoft SQL Server databases OLEDB technology is versatile... SqlDependency OracleError SqlError OracleException SqlException OracleTransaction INTRODUCTION TO ORACLE NET CONNECTIVITY SqlTransaction The OracleConnection class, for example, provides the developer a set of methods to connect to the Oracle database The OracleCommand class allows the developer to set up an SQL statement or stored procedure to execute Finally, the OracleDataAdapter class allows ODP.NET. .. OLEDB Provider for Oracle The Microsoft OLEDB Provider for Oracle (MSDAORA) is Microsoft’s architectural equivalent of the OraOLEDB provider It only supports Oracle database versions up to 7i, with limited support for version 8i Note MSDAORA has been deprecated because it uses OCI version 7.0, which is no longer supported by Oracle Using ODBC in Unmanaged Code ODBC is a standard data access protocol... in your application, because some providers, like the Oracle Objects for OLE (OO4O) provider, do not use ADO/ADO.NET but instead use a proprietary set of classes to access the database In short, it all depends on what you need for your project As an example, if you needed to receive Oracle database change notifications in your project, you would be better off using ODP.NET instead of OLEDB.NET And if... even ODP.NET all translate into OCI calls Even Oracle s own management tools ultimately depend on the OCI Thus, the OCI can be relied on to expose all possible functionality in Oracle With Microsoft’s NET Managed Provider for Oracle recently deprecated, NET developers are now turning to ODP.NET, the managed provider from Oracle that offers exceptional performance and yet exposes all the advanced Oracle . with Oracle
Database from Microsoft .NET
BOOKs fOR PROfessIOnALs BY PROfessIOnALs
®
Pro ODP .NET for Oracle Database 11g
Dear Reader,
Oracle Data Provider.
Databases / Oracle
User level:
Intermediate–Advanced
Edmund Zehoo
THE APRESS ROADMAP
Applied Mathematics
For
Database Professionals
Pro ODP. NET for
Oracle
Ngày đăng: 17/02/2014, 17:20
Xem thêm: Tài liệu Pro ODP.NET for Oracle Database 11g pdf, Tài liệu Pro ODP.NET for Oracle Database 11g pdf, Using PL/SQL and .NET CLR Stored Procedures with ODP.NET