Send feedback on this topic.
Teradata.Client.Provider
TdConnection Class
Members  Example 



Teradata.Client.Provider Namespace : TdConnection Class
TdConnection class represents a connection or session to Teradata. It is used to specify the session characteristics such as Session Character Set or User Id when including a TdConnection.ConnectionString in the constructor.
Object Model
TdConnection ClassTdTransaction ClassTdCommand ClassTdQueryBand Class
Syntax
Remarks
Represents a public connection object to Teradata. See ADO.NET documentation on implementation requirements. It implements Data.IDbConnection which is part of the ADO.NET specification. TdConnection derives from the Component class so that it can eventually be used on a design surface (e.g. Visual Studio .NET). Also note that the Component is marshaled by reference which indicates TdConnection also will be marshaled by reference.

TdConnection is a Component and therefore implements the IDisposable interface. It is highly recommended that TdConnection.Dispose or TdConnection.Close be called before an instance of this class is released for garbage collection. Garbage collection is not deterministic and therefore valuable Teradata resources (i.e. session) might not be released immediately. Also TdConnection.Dispose or TdConnection.Close returns the Teradata session back to the pool if connection pooling is enabled. See TdConnection.ConnectionString for details on connection pooling.

TdConnection also allows for explicit transactions via the TdConnection.BeginTransaction method.

Example
The following example creates a TdConnection class and opens a session to Teradata. The "Show Table Customers" SQL statement is executed and the result is assigned to the customers variable.

class Example
{
   static void Main(String[] args)
   {
      TdConnection cn = null;
            
      try
      {
         cn = new TdConnection("Data Source=Teradata1;User Id=ab;Password=ab;");
         cn.Open();
		
         TdCommand cmd = new TdCommand("Show Table Customers", cn);
            
         String customers = (String) cmd.ExecuteScalar();
            
         cmd.Dispose();
      }
      catch(TdException e)
      {
         Debug.WriteLine(e.Message);
      }
      finally
      {
         if (null != cn)
         {
            cn.Close();
         }
      }
   }
}
Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Data.Common.DbConnection
            Teradata.Client.Provider.TdConnection

Requirements

Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019

See Also

Reference

TdConnection Members
Teradata.Client.Provider Namespace
TdCommand Class
TdDataReader Class
TdDataAdapter Class