Download presentation
1
ODP.NET
2
Access Oracle from .NET Using C#
Oct 2004 Access Oracle from .NET Using C# Alex Hoyos
3
Agenda Define MS .NET Web development and .NET (basic stuff) IDE used
Different ways of talking to Oracle from .NET ODP.NET – crack it open and get it ready Samples
4
What is MS NET. Architecture
IL (Intermediate Language), CLR (Common Language Runtime), Base Class Library (BCL) is a common library used by all languages, GC (Garbage collection) is the responsibility of the CLR, not the language. .NET 20K feet high view…
5
CLR - COMMON LANGUAGE RUNTINE
What is MS .NET VB C++ C# J# .. ASP.NET Web Forms Web Services Windows FORMS ODP.NET ADO.NET BASE CLASS LIBRARY CLR - COMMON LANGUAGE RUNTINE OPERATING SYSTEM
6
ODP + .NET lingo Namespaces:
Assembly: Microsoft’s term for the module that is created when a DLL or .EXE is complied by a .NET compiler. ODP.net Assembly is Oracle.DataAccess.dll Namespaces: Oracle.DataAccess.Client (e.g. OracleConnection) Oracle.DataAccess.Types (e.g. OracleClob Class)
7
Oracle: Best Database for .NET
ODP.NET allows full access to .NET No limitation to using .NET functionality. Still requires you install the Oracle Client Software (9 or above)
8
Oracle and .NET Data Access
Oracle Data Provider for .NET (ODP.NET) Developed by Oracle Best performing provider Exposes the most Oracle DB features Based upon Microsoft ADO.NET spec 3rd party Oracle providers Microsoft .NET Data Provider for Oracle (Microsoft) Connect for .NET (DataDirect) Other Oracle data access methods OLE DB .NET via OLE DB ODBC .NET via ODBC
9
ODP.NET Basics Available today in production for free
Original release: Dec. 2002 Can be used with Oracle8, Oracle8i, Oracle9i, and Oracle10g database servers Database server can be on Unix, Linux, Windows, etc. Database client on Windows Supports VS.NET 2002 and 2003 Supports .NET Framework 1.0 and 1.1 ODP.NET requires the Oracle client to be installed to be installed in the middle-tier/client with the .NET Framework. You can download the production version today from OTN. ODP.NET can remotely access Oracle8, 8i, 9i, and 10g DB servers. These DB servers do not have to be running on Windows, but can run on any OS that the Oracle DB supports. The DB server does not need to have ODP.NET installed, only the middle-tier/client. ODP.NET supports all .NET programming languages (C#, VB .NET, C++ .NET, etc.), all .NET Framework versions (1.0 and 1.1), and VS.NET versions (2002 and 2003)
10
ODP.NET Object Model Disconnected Connected Layer Data Layer (ODP.NET)
Oracle DataAdapter OracleCommand Builder DataSet Oracle DataReader Oracle Command Oracle Transaction Oracle Connection Oracle
11
ODP.NET Features Full PL/SQL support Native Oracle data types
Packaged, non-packaged, anonymous, autonomous *Batch SQL available with anonymous PL/SQL Native Oracle data types LOBS, REF Cursors, BFiles, N-data types, Dates, TimeStamps, Longs, Raws, etc. Safe type mapping to .NET data types *Connection pooling Min, Max, Timeout, Lifetime, Increment, Decrement Here are some of the ODP.NET features that were not previously available to ADO, OLE DB .NET, nor ODBC .NET users: More robust anonymous (use PL/SQL blocks in .NET code) PL/SQL support Native Oracle types and safe type mapping Connection Pooling Configuration PL/SQL can be used more flexibly with ODP.NET. Anonymous PL/SQL allows the client to batch SQL calls to the DB. When you embed multiple commands within anonymous PL/SQL, only one roundtrip to the database is made, thereby improving data access performance. Native Oracle types allow users to use Oracle data types within their .NET programs. This makes using Oracle data easier and much more flexible from .NET. It saves developers and applications from doing unnecessary conversions to .NET data types if they are not needed. Each native Oracle data type can be mapped to a respective .NET data type. Because Oracle data types tend to be higher precision than .NET types, Oracle allows conversion between the two types without losing data. This is known as safe type mapping. For example, Oracle Number can hold 38 digits, whereas .NET Decimal only holds 28. Safe type mapping allows converting Oracle Number to .NET byte array or .NET string and back to Oracle Number without losing any data. Creating DB connections is resource intensive. As such, connection pooling is an invaluable performance tuning option. Previously, .NET developers could only set timeout values for their connection pools. With ODP.NET, connection pools are very flexible to configure for any type of application user load. * Performance tip
12
ODP.NET Installation The Oracle.DataAccess.dll assembly is installed in the ORACLE_ BASE\ORACLE_HOME\bin directory. Documentation and the readme.txt are installed in the ORACLE_BASE\ORACLE_HOME\ODP.NET\doc directory. Samples are provided in the ORACLE_BASE\ORACLE_HOME\ODP.NET\Samples directory. Here are some of the ODP.NET features that were not previously available to ADO, OLE DB .NET, nor ODBC .NET users: More robust anonymous (use PL/SQL blocks in .NET code) PL/SQL support Native Oracle types and safe type mapping Connection Pooling Configuration PL/SQL can be used more flexibly with ODP.NET. Anonymous PL/SQL allows the client to batch SQL calls to the DB. When you embed multiple commands within anonymous PL/SQL, only one roundtrip to the database is made, thereby improving data access performance. Native Oracle types allow users to use Oracle data types within their .NET programs. This makes using Oracle data easier and much more flexible from .NET. It saves developers and applications from doing unnecessary conversions to .NET data types if they are not needed. Each native Oracle data type can be mapped to a respective .NET data type. Because Oracle data types tend to be higher precision than .NET types, Oracle allows conversion between the two types without losing data. This is known as safe type mapping. For example, Oracle Number can hold 38 digits, whereas .NET Decimal only holds 28. Safe type mapping allows converting Oracle Number to .NET byte array or .NET string and back to Oracle Number without losing any data. Creating DB connections is resource intensive. As such, connection pooling is an invaluable performance tuning option. Previously, .NET developers could only set timeout values for their connection pools. With ODP.NET, connection pools are very flexible to configure for any type of application user load. * Performance tip
13
Visual Studio .NET Integration
Dynamic Help ODP.NET documentation available – Hit F1 key Intellisense Connection pooling is enabled in ODP.NET (by default).
14
ODP.NET Connection Options
Proxy user authentication OracleConnection con = new OracleConnection(); con.ConnectionString = "User Id=customer;Password=lion;" + "Data Source=oracle;Proxy User Id=appserver;Proxy Password=eagle; "; con.Open(); Operating System Authentication con.ConnectionString = "User Id=/;Data Source=oracle;"; Here are some of the ODP.NET features that were not previously available to ADO, OLE DB .NET, nor ODBC .NET users: Proxy user authentication Named parameter binding and array binding DataAdapter Requery Proxy user authentication allows a proxy user to connect to the database on behalf of client users. For example, an airline may want a customer, John, to be able to log into its website with “gold” level privileges. Using this feature, the .NET application will connect to Oracle as the proxy user (gold), but the client user’s identity (John) will also be passed. This controls the security of middle-tier applications by preserving client identities and privileges through all tiers, and auditing actions taken on behalf of clients. Application scalability is maintained as the ODP.NET connection pool is based on the proxy user, not the client user. Parameters can be bound to PL/SQL or SQL calls either through using named parameters or by sequential position. Array binding improves application performance by reducing the number of roundtrips for SELECTs and DML. For example, without array binding, updating 100 rows would require 100 DB server roundtrips. With array binding, only one roundtrip is necessary to do all 100 updates. This makes applications perform considerably faster. ODP.NET has the flexibility to bind parameters by position or name, whichever best fits the developer’s preference. DataAdapter Requery allows developers to reuse the same query result for multiple data fills of DataSet. This feature saves applications from having to re-query the DB for the same set of data. * Performance tip
15
ODP.NET Connection Connection pools are created by the connection pooling service using the ConnectionString as a signature to uniquely identify a pool. OracleConnection con = new OracleConnection(); con.ConnectionString = "User Id=scott;Password=tiger;Data Source=oracle;" + "Min Pool Size=5;Max Pool Size=20;Connection Lifetime=120;” + “Connection Timeout=60; Incr Pool Size=5; Decr Pool Size=2"; con.Open(); NOTES: Connection Lifetime = Maximum life time (in seconds) of the connection (default 0) Connection Lifetime enforced when a connection is going back to the connection pool. Connections are closed every three minutes (connection Lifetime..) Here are some of the ODP.NET features that were not previously available to ADO, OLE DB .NET, nor ODBC .NET users: PL/SQL Associative Array InitialLOBFetchSize property The associative array, also known as index-by table, is a PL/SQL data type similar to a hash table. It can be bound as an ODP.NET parameter and passed as an array to .NET. Designing ODP.NET applications to optimize LOB retrieval has added flexibility with the InitialLOBFetchSize property. Normally, ODP.NET defers fetching LOB data from the DB until the last minute. This method can improve application responsiveness by spacing out data retrieval over time, but also results in more database round trips. In some cases, fewer round trips by retrieving most of the LOB data all at once are more beneficial to overall performance. Using the InitialLOBFetchSize property, developers can set the amount of LOB data to retrieve on the first round trip for all LOBs in a query. If the property is set to zero, LOB retrieval returns to its deferred method. * Performance tip
16
Workshop Example VS.NET
NOTE: Right-click and select “open in new Window” to prevent the current powerpoint from being overlaid and thus allowing you to continue. If you have a popup blocker, this may prevent a new window from opening. E.g. with Google Popup blocker, you need to press the ctrl key simultaneously. WebEx Pre-recorded Sessions Create Skeleton ASP.NET Web Application Add Populate Dept functionality Add Insert Dept Functionality Execute Application
17
ODP.NET Performance and Scalability Tips
Close all ODP.NET objects when finished (e.g. OracleConnection) Do not count on the garbage collector to do this automatically Use anonymous PL/SQL when batching commands Makes only one DB round trip Use associative arrays to bind parameters Use FetchSize (OracleDataReader) and RowSize (OracleCommand) to tune data retrieval performance Use InitialLOBFetchSize and InitialLongFetchSize to tune LOB and LONG retrieval performance
18
Performance Use Anonymous PL/SQL blocks.
19
FAQ Q: Can ODP.NET work with Oracle8, Oracle8i, Oracle9i, and Oracle10g database (DB) servers? Yes, but you will need to use an Oracle9i Release 2 client or higher
20
FAQ Q: Do I need to install ODP.NET on my Oracle DB server?
A: No. You only need to install ODP.NET on your client or middle-tier machine, wherever you use the .NET Framework.
21
“Thank you.” 1 38 2
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.