skip to main content
Configuring the ADO.NET Client : Connecting to a Database : Example 1: Using the Provider-Specific Objects
 

Example 1: Using the Provider-Specific Objects

The following example uses the provider-specific objects to connect to a database using the Oracle data provider from an application developed in Visual Studio using C#.
1. In the Solution Explorer, right-click References, and then select Add Reference.
2. Select the OpenAccess SDK data provider in the component list of the Add Reference dialog box.
3. Click OK. The Solution Explorer now includes DDTek.OpenAccess, the assembly for the OpenAccess SDK data provider.Solution Explorer window with the Oracle data provider added.
4. Add the data provider’s namespace to the beginning of your application, as shown in the following C# code fragment:
// Access database
using System.Data;
using OpenAccess.dll;
5. Add the connection information for your server and exception handling code, and close the connection, as shown in the following C# code fragment:
OpenAccessConnection DBConn = new OpenAccessConnection("Host=test; Port=19986;User ID=test01;Password=test01");
try
{
DBConn.Open();
Console.WriteLine ("Connection successful!");
}
// Display any exceptions ddd
catch (OpenAccessException ex)
{
// Connection failed
Console.WriteLine(ex.Message);
return;
}
6. Close the connection.
// Close the connection
Conn.Close();