March 2008
Intermediate to advanced
982 pages
22h 43m
English
You want to connect to an Oracle database.
You can connect to an Oracle database using the Oracle .NET data provider, the OLE DB .NET data provider, or the ODBC .NET data provider.
The solution creates and opens a connection to an Oracle database using the Oracle .NET data provider, OLE DB .NET data provider, and ODBC .NET data provider in turn. In each case, information about the connection is displayed from the properties of the connection object.
The solution requires a reference to the System.Data.OracleClient assembly.
The C# code in Program.cs in the project ConnectOracle is shown in Example 1-8.
Example 1-8. File: Program.cs for ConnectOracle solution
using System;
using System.Data.OracleClient;
using System.Data.OleDb;
using System.Data.Odbc;
namespace ConnectOracle
{
class Program Interprocess communication (IPC)
{
static void Main(string[] args)
{
// Connect using .NET data provider for Oracle
string oracleConnectString =
"Data Source=ORCL;User Id=hr;Password=password;";
using (OracleConnection connection =
new OracleConnection(oracleConnectString))
{
connection.Open( );
// Return some information about the server.
Console.WriteLine("---Microsoft .NET Provider for Oracle---");
Console.WriteLine("ConnectionString = {0}\n", oracleConnectString);
Console.WriteLine("State = {0}", connection.State);
Console.WriteLine("DataSource = {0}", connection.DataSource); Console.WriteLine("ServerVersion = {0}", connection.ServerVersion); ...Read now
Unlock full access