Connecting to a Database
- Last Updated: April 16, 2026
- 3 minute read
- ADO.NET
- Documentation
Once the data provider is installed, you can connect from your application to your database with a connection string. See the appropriate data provider section for connection string options.
Example A: 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#.
-
In the Solution Explorer, right-click References, and then select Add Reference. The Add Reference dialog box appears.

-
Select the Oracle data provider in the component list of the Add Reference dialog box and click OK.
The Solution Explorer now includes DDTek.Oracle, the assembly name of the Oracle data provider.

-
Add the data provider’s namespace to the beginning of your application, as shown in the following C# code fragment:
// Access Oracle using System.Data; using DDTek.Oracle; -
Add the connection information for your server and exception handling code, and close the connection, as shown in the following C# code fragment:
OracleConnection DBConn = new OracleConnection("Host=Accounting1;Port=1521;User ID=scott;Password=tiger;Service Name=sales.us.acme.com"); try { DBConn.Open(); Console.WriteLine ("Connection successful!"); } // Display any exceptions catch (OracleException ex) { // Connection failed Console.WriteLine(ex.Message); return; } -
Close the connection.
// Close the connection DBConn.Close();
Example B: Using the Common Programming Model
The following example illustrates connecting to an Oracle database from an application developed in Visual Studio using C# and the Common Programming Model.
- Check the beginning of your application. Ensure the .NET Framework namespaces are present. For example:
// Access Oracle using factory using System.Data; using System.Data.Common; - Add the connection information of your server and exception handling code and close the connection. For example:
DbProviderFactory factory=DbProviderFactories.GetFactory("DDTek.Oracle");
DbConnection Conn = factory.createConnection();
Conn.ConnectionString = "host=Accounting1;Port=1521;Service Name=test;User ID=test01; Password=test01";
try
{
Conn.Open();
Console.WriteLine("Connection successful!");
}
catch (Exception ex)
{
// Connection failed
Console.WriteLine(ex.Message);
}
// Close the connection
Conn.Close();
Example C: Using the DataDirect Common Assembly
You can optionally include the DataDirect Common Assembly if you want to use features such as DataDirect Bulk Load in an application that conforms to the Common Programming Model. See Using DataDirect Bulk Load for information about how to use DataDirect Bulk Load with your application.
The following example illustrates how to use the DataDirect Common Programming Assembly in an application developed in Visual Studio using C# and the Common Programming Model.
-
Check the beginning of your application. Ensure the .NET Framework and DataDirect Connect for ADO.NET namespaces are present.
// Access Oracle using factory using System.Data; using System.Data.Common; using DDTek.Data.Common; -
Add the connection information of your server and exception handling code and close the connection.
// This code does a bulk copy operation from one
// Oracle database to another
DbProviderFactory factory = DbProviderFactories.GetFactory("DDTek.Oracle")
DbConnection Conn1 = factory.CreateConnection();
Conn1.ConnectionString = "... Oracle Server ....";
Conn1.Open();
DbCommand command = "SELECT ProductID, Name FROM Products";
DbDataReader reader = command.ExecuteReader();
using (DbConnection Conn2 = factory.CreateConnection())
Conn2.ConnectionString = " ... Oracle Server ....";
Conn2.Open();
using (DbBulkCopy bulkCopy = new DbBulkCopy(Conn2) {
bulkCopy.DestinationTable = "ProductsMirror";
try {
bulkCopy.WriteToServer(reader);
}
catch {
Console.WriteLine(ex.Message);
}
}