Microsoft OracleClient to ODP.NET Application Migration: Code Migration
Now that installation and client setup is complete, you can now start migrating your Microsoft OracleClient application code to ODP.NET. The first thing your application will need is a reference to ODP.NET.
Add an ODP.NET Reference
Open your application in Microsoft Visual Studio.
Go to Solution Explorer. Right click the References node and choose Add Reference.
The Add Reference window will open. Under the .NET tab, scroll down and select Oracle.DataAccess under Component Name. Click Ok.
Oracle.DataAccess will now be present under the References node. You can now reference ODP.NET from within your .NET application.
Add the ODP.NET Namespace
Adding the ODP.NET namespace makes referencing ODP.NET objects easier. In this step, we will remove the Microsoft OracleClient namespace and replace it with the ODP.NET namespace.
Find the Microsoft OracleClient namespace reference and replace it with an ODP.NET reference. Optionally, if you plan to use ODP.NET-specific data types, you should add that namespace also.
Find: using System.Data.OracleClient;
Replace with: using Oracle.DataAccess.Client;
Optionally add: using Oracle.DataAccess.Types;
Nearly all Microsoft OracleClient connection string attributes map to ODP.NET connection string attributes. Most applications will not need to make any changes to start using ODP.NET.
To migrate to ODP.NET, remove these attributes if they are part of the Microsoft OracleClient connection string.
Integrated Security-- Set " User Id=/" in the ODP.NET connection string for the equivalent operating system authentication.
Unicode-- This setting is unnecessary because ODP.NET is always Unicode aware
If you use the "Server" attribute, change its name to " Data Source" for the ODP.NET equivalent attribute.
Parameter Binding by Name
Both Microsoft OracleClient and ODP.NET use the colon to bind parameters and bind parameters by name. While ODP.NET supports binding by name, it binds by position by default. To match Microsoft OracleClient's parameter name binding behavior, add the following line to your code after each OracleCommand instantiation that you bind parameters to:
OracleCommand.BindByName = true;
OracleCommand.BindByName = true
Code Migration Conclusion
By now, you have completed the great majority of the work needed to migrate your Microsoft OracleClient application to ODP.NET. There are a few class differences between the two providers and any additional changes are generally straightforward. If you have any additional questions about Microsoft OracleClient to ODP.NET migration, feel free to email the ODP.NET product manager, Alex Keh (alex.keh [at] oracle.com).