Download presentation
Presentation is loading. Please wait.
1
Опит в използването на ODP.NET с Oracle 9i
Лектор: Иван Симеонов ТехноЛогика ЕООД
2
Какво е Oracle Data Provider for .NET (ODP.NET)
ASP.NET VB.NET C# C++.NET OLE DB .NET ODBC .NET ODP .NET ORACLE OLE DB ORACLE ODBC The introduction of the Microsoft .NET Framework has produced a new Windows application server environment different from COM. With COM, data can be accessed from an Oracle database through either Oracle Objects for OLE (OO4O), ADO/OLE DB, or ODBC. In a .NET environment, users still can access the Oracle database via OLE DB and ODBC using a data access bridge provided by Microsoft. For OLE DB, this bridge is OLE DB .NET; For ODBC, the bridge is ODBC .NET. These bridges provide interoperability between the managed .NET layer and unmanaged COM or Win32 layer. The Oracle Data Provider for .NET (ODP.NET) represents the third method for accessing the Oracle database. DIFFERENCES WITH OTHER .NET DATA PROVIDERS Among the three data access methods, ODP.NET is the most native to the .NET environment, bypassing the need for OLE DB or ODBC. It features high performance access to the Oracle database, while providing access to advanced Oracle functionality not available through OLE DB .NET and ODBC .NET. Similar to OLE DB .NET and ODBC .NET, ODP.NET can be used from any .NET language, such as C# and Visual Basic .NET. An important distinction is that ODP.NET does not use an extra data access bridge; thus, it will have better performance than OLE DB .NET and ODBC .NET. Additionally, because these .NET bridges are built for generic data sources, they do not provide full access to advanced database functionality. These three .NET data providers are shown in Figure. ORACLE DB
3
ODP.NET Обектен модел Disconnected Layer Connected Layer (ODP.NET)
Data Layer Oracle DataAdapter OracleCommand Builder DataSet Oracle DataReader Oracle Command Business Object Oracle Transaction Oracle Connection Oracle
4
Основни характеристики на ODP.NET
Full PL/SQL support Packaged, non-packaged, anonymous, autonomous Batch SQL available with anonymous PL/SQL Native Oracle data types LOBs, REF Cursor, Date, TimeStamps, Long, Raw, etc. Connection pooling Min, Max, Timeout, Lifetime, Increment, Decrement Transactions Enterprise Services via Oracle Services for MTS Savepoints Globalization Full Unicode support Client settings are used to display Oracle data in locale-specific manner Transparent application failover Notification callbacks 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.
5
Основни характеристики на ODP.NET - продължение
Parameters PL/SQL Associative Array data type Parameter Array binding Named and positional parameters XML DB XML repository Native XMLType XML stored as CLOB or object Schema and non-schema-based XML Views PL/SQL Associative Array Parameter Array Binding Named parameter binding and array binding 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. 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 DML primarily. 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. XML DB is a high performance XML storage and retrieval technology in the Oracle DB. XML DB stores XML natively in the DB with its own data type, XMLType. ODP.NET exposes XMLType as a native type within .NET to manipulate XML and share XML with Microsoft’s XML services, such as XMLReader. ODP.NET can access relational and object-relational data as XML with the ability to query and save XML from the database easily.
6
Oсновни предимства на ODP.NET
Multiple Active Result Sets (MARS) Native XML Data Type Result Set Retrieval Tuning Options Configurable LOB Retrieval Array Parameters
7
Oracle Helper ExecuteDataSet – 6 overloads
ExecuteFunction – 9 overloads ExecuteReader – 6 overloads ExecuteScalar – 6 overloads ExecuteNonQuery – 6 overloads ExecuteXMLReader – 6 overloads
8
Проблеми с ODP.NET Липсва DeriveParameters за PL/SQL процедури
PLSQL Associative Arrays без стойност на елемент Не поддържа varray като параметър ExecuteScalar не работи с PL/SQL Functions без RefCursor Разлика в типовете данни
9
Добри практики при използването на ODP.NET
Използвайте connection pooling Отстранявайте ODP.NET обектите, когато приключите работа Минимизирайте roundtrips Оптимизиране на single statement (SELECT) Използвайте FetchSize (OracleDataReader) и RowSize (OracleCommand) Използвайте DataAdapter.Requery Намалява roundtrips при повторно изпълнение на команда
10
Добри практики при използването на ODP.NET - продължение
Оптимизиране на multi-statement Изпълнявате много и различни команди? Използвайте anonymous PL/SQL Използвайте групови команди Изпълнявате една команда много пъти? Използвайте parameter array binding Използвайте PL/SQL associative arrays
11
Добри практики при използването на ODP.NET - продължение
Използвайте OracleRefCursor class Данните се извличат, когато е необходимо Използвайте Oracle LOB classes (DML) Няма необходимост да изтегляте данните за да променяте или добавяте LOBs Желаете данните в LOB на един път? Използвайте InitialLOBFetchSize, за да оптимизирате извличането на LOB Желаете да извлечете LOB по-късно? По подразбиране, ODP.NET използва LOB locators
12
Добри практики при използването на ODP.NET - продължение
Използвайте PL/SQL пакети Управлявайте транзакциите от .NET Когато е възможно, използвайте multiple RefCursors Използвайте собствен error handling (Exceptions.ApplicationBlock) …
13
Други .NET Providers за Oracle
Microsoft .NET Data Provider for Oracle Corelab OraDirect .NET Data Provider DataDirect Connect for .NET
14
Кой .NET Provider да използваме
За малки приложения и бърза разработка – MS Data Provider for Oracle За пълно използване на възможностите на Oracle DB и висока производителност – ODP.NET
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.