skip to main content
Configuring the ADO.NET Client : Connecting to a Database : Example 2: Using the Common Programming Model
 

Example 2: Using the Common Programming Model

The following example illustrates connecting to an OpenAccess SDK Server from an application developed in Visual Studio using C# and the Common Programming Model.
1. Check the beginning of your application. Ensure the ADO.NET namespaces are present.
// Access OpenAccess Server using factory
using System.Data;
using System.Data.Common;
2. Add the connection information of your server and exception handling code and close the connection.
DbProviderFactory factory=DbProviderFactories.GetFactory("DDTekOpenAccess");
DbConnection Conn = factory.createConnection();
Conn.ConnectionString = "host=test;Port=19986;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();
For information about using connection strings and connection string options, refer to the OpenAccess SDK Client Reference.