skip to main content
Using the ADO.NET Client : Connecting to a Data Source
 

Connecting to a Data Source

Once the ADO.NET Client is installed, you can connect from your application to your data source with a connection string.
The following example illustrates connecting to the underlying database using the ADO.NET Client from an application developed in Visual Studio.
If you are using Visual Studio:
1. In the Solution Explorer, right-click References; then, click Add Reference.
2. Select DataDirect OpenAccess SDK Client for .NET in the component list.
3. Click OK. The application references now include DDTek.OpenAccess, the assembly name for the ADO.NET Client.
4. Check the beginning of your application. If the ADO.NET Client namespace is not present, add it, as shown in the following C# code fragment:
// Access OpenAccess Server
using System.Data;
using DDTek.OpenAccess;
5. Add the connection information for your server and exception handling code, as shown in the following C# code fragments. (See Specifying Connection Options for the connection string options.)
DBConn = new OpenAccessConnection("Host=myhost;Port=myport;
User ID=
myUID;Password=myPWD;ServerDataSource=mySDSN");
try
{
DBConn.Open();
Console.WriteLine ("Connection successful!");
}
// Display any exceptions
catch (OpenAccessException ex)
{
// Connection failed
Console.WriteLine (ex.Message);
return;
}
6. Close the connection.
// Close the connection
DBConn.Close();