DAA with Oracle

Jul 22, 2007 at 12:49 PM
Hello, can you please guide me on how to use DAA with Oracle, do I need to install some other drivers or something to connect to Oracle Database of I only need Data Access Application Block dlls to connect to Oracle database and call the stored procedures.

I am using Microsoft Enterprise Library 3.1.

If possible kindly provide me any examples or samples with Oracle.

Thanks and best regards
Jul 23, 2007 at 12:05 PM
Well first thing you need is the oracle client installed. I recommend always getting the latest version.

You can use either the Microsoft provider (System.Data.OracleClient) or the one from Oracle (Oracle.DataAccess.Client), though the latter will require additional resources external to the .NET runtime.

Here are two connection strings defined in the config file:
<add name="msConnectionString"
connectionString="Data Source=dbsid;Persist Security Info=True;User ID=dbuser;Password=db_psswd;Unicode=True"
providerName="System.Data.OracleClient" />
<add name="oraConnectionString" connectionString="Data Source=dbsid;User Id=dbuser;Password=db_psswd;"
providerName="Oracle.DataAccess.Client" />

Here is some sample code:

//Database db = DatabaseFactory.CreateDatabase("msConnectionString"); // create db defined in the config file
Database db = DatabaseFactory.CreateDatabase("oraConnectionString"); // create db defined in the config file
Console.WriteLine("Date from db: {0}", db.ExecuteScalar(CommandType.Text, "select sysdate from dual"));

Console.WriteLine("\nPress ENTER to continue");
Jul 23, 2007 at 3:13 PM

In addition to Greif's information, you can browse the ADO.NET 2.0 oracle client topic from MSDN, which includes system requirements like the Oracle database client, from http://msdn2.microsoft.com/en-us/library/77d8yct7(VS.80).aspx. You must know that the DAAB really builds on top of ADO.NET 2.0 and it doesn't manage the actual communication with the database, using ADO.NET's components instead.

DAAB will let you write DB agnostic code through the Database class, and in this case the only "oracle-specific" aspect of your application will be the connection string. However, if you need some Oracle specific feature, and if you know that you will always use an Oracle database, you can cast your database to OracleDatabase and use the extended API available in that class like using Oracle specific parameter types. Additionally, you can learn about the Oracle specific configuration that let's you map prefixes in database objects' names to oracle package names.