Client Interfaces Guide > Connecting to TDV Server through ADO.NET > Sample Code for Testing of an ADO.NET Driver > Create a CompositeConnection Object
 
Create a CompositeConnection Object
This creates a CompositeConnection object with a parameter object called CompositeConnectionStringBuilder. When it has been created, you must call the open method to connect to the server. If there is an exception when connecting to the server, the sample code catch returns to try the connection again.
Always use the Close method to close the conn object when finished with it. Use the conn object to access the TDV Server.
To create a CompositeConnection object using compositeConnectionStringBuilder
1. Create a class called BaseTest. For example:
public class BaseTest
{
 
protected CompositeConnection conn;
protected CompositeConnectionStringBuilder builder;
public BaseTest()
{
}
}
 
This code defines a constructor method.
2. Add code to create more examples.
For example, build a CompositeConnectionStringBuilder object that requires a BuildConnectionString method to feed the object:
public class BaseTest
{
public BaseTest()
{
// Build the CompositeConnectionStringBuilder object when calling the construction method.
BuildConnectionString();
}
// Construct the CompositeConnectionStringBuilder object.
private void BuildConnectionString()
{
String connstring = “host=localhost;port=9401;user=admin;password=admin;domain=composite;datasource=examples”;
builder = new CompositeConnectionStringBuilder(connstring);
}
}
 
3. In the BaseTest class, create a CompositeConnection object, and create Open and Close methods and a CompositeConnection object with the following code:
// Create CompositeConnect
protected void Open()
{
try
{
conn = new CompositeConnection(builder);
conn.Open();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
 
protected void Close()
{
try
{
if (conn.State == ConnectionState.Closed)
return;
conn.Close();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
 
protected CompositeConnection GetConnection()
{
if (conn == null || conn.State == ConnectionState.Closed)
Open();
return conn;
}