Send feedback on this topic.
Teradata.Client.Provider
Close Method (TdConnection)
Example 



Teradata.Client.Provider Namespace > TdConnection Class : Close Method
Closes the connection to Teradata.
Syntax
'Declaration
 
Public Overrides NotOverridable Sub Close() 
'Usage
 
Dim instance As TdConnection
 
instance.Close()
public override void Close()
public:
void Close(); override 
Remarks

If the connection is in closed state, the method simply returns. However, if the connection is open, the Close method either disconnects (logs off) from Teradata or returns the Teradata session back to the pool. In either case, any active explicit transaction is rolled back by Teradata or the .NET Data Provider for Teradata. See TdConnection.StateChange event for additional information about events generated by the Close method.

Before calling Close, it is important that the command object is closed (TdCommand.Dispose) first before closing the connection to Teradata. However, if the Close is called before the command object is closed, the provider will perform the following actions:

With the introduction of Redrive and Recoverable Network Protocol, the TdConnection.Close may be used to cancel a reconnection that may not be completed.

If the TdConnection.State is Connecting while TdConnection.Close is executed, the reconnection will be scheduled for cancellation. During reconnection the acknowledgement of the TdConnection.Close may be delayed a maximum of period of time defined in TdConnectionStringBuilder.RecoveryMaximumInterval.

Example
The following example creates a TdConnection class and illustrates the use of Open and Close methods:

public Boolean TestConnectivity(String connectionString)
{	
    Boolean connectivity = false;
            
    TdConnection cn = new  TdConnection(connectionString);
            
    try
    {
       cn.Open();
       connectivity = true;
    }
    catch(Exception e)
    {
       connectivity = false;
    }
            
    cn.Close();
            
    return connectivity;	
}
Requirements

Target Platforms: Windows 7, Windows 8, Windows 8.1, Windows 10, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2

See Also

Reference

TdConnection Class
TdConnection Members