Send feedback on this topic.
Teradata.Client.Provider
OpenAsync(CancellationToken) Method
Example 



Teradata.Client.Provider Namespace > TdConnection Class > OpenAsync Method : OpenAsync(CancellationToken) Method
A Threading.CancellationToken used to indicate that the asynchronous operation should be canceled.
Asynchronously opens a Teradata session using the attributes specified via the TdConnection.ConnectionString.
Syntax
'Declaration
 
Public Overloads Overrides NotOverridable Function OpenAsync( _
   ByVal cancellationToken As CancellationToken _
) As Task
'Usage
 
Dim instance As TdConnection
Dim cancellationToken As CancellationToken
Dim value As Task
 
value = instance.OpenAsync(cancellationToken)
public override Task OpenAsync( 
   CancellationToken cancellationToken
)
public:
Task^ OpenAsync( 
   CancellationToken cancellationToken
) override 

Parameters

cancellationToken
A Threading.CancellationToken used to indicate that the asynchronous operation should be canceled.

Return Value

Returns a Task that may be awaited or monitored for completion.
Exceptions
ExceptionDescription
The TdConnection is disposed.
TdConnection is not in the Closed state or the connection string is not a valid connection string, or an Open operation is already in progress.
Remarks

If this function generates a runtime exception, that exception will be wrapped in an AggregateException within the returned Task.

After calling OpenAsync, TdConnection.State will return Connecting until the returned Task is completed. Then, if the connection was successful, State will return Open. If the connection fails, State will return Closed.

A call to TdConnection.Close while an OpenAsync task is executing will attempt to cancel the task before closing the connection.

If you wish to be able to cancel the OpenAsync task you must create a Threading.CancellationTokenSource and pass its Threading.CancellationTokenSource.Token to this method. To cancel the task, call the Threading.CancellationTokenSource.Cancel method.

If the TdConnectionStringBuilder.ConnectionTimeout is reached before the task completes the task will be cancelled.

If a connection to the Teradata Database has already been established when cancellation is requested the cancel request will be ignored.

If connection pooling is turned off, TdConnection attempts to establish a new Teradata session. Otherwise, the ConnectionPool either returns an existing Teradata Session or creates a new Teradata session if the number of pooled sessions is less than Max Pooled Size.

If the connection string has a Database attribute, the TdConnection.ChangeDatabase method is called immediately after a session is opened to Teradata. This will result in additional roundtrips to the Teradata Database. We strongly recommend that you modify the User (See Teradata manual for information on Create User or Alter User) and add a default database. This will enhance the overall performance of opening a connection to the Teradata Database. Please note that ChangeDatabase method is called independently of whether the connection pooling is turned on or off and errors generated as a result of an invalid supplied ConnectionString Database attribute are ignored.

If the password has expired and pooling is turned off, then an TdConnection.InfoMessage event is triggered. The application should respond to the event by:

1) Change the password
2) Close the TdConnection
3) Open the TdConnection

Alternatively, the application can set the ‘New Password’ attribute in the connection string.

Example
The following example creates a TdConnection class and illustrates the use of OpenAsync and Close methods.
public async Task<Boolean> TestConnectivityAsync(String connectionString)
{	
   Boolean connectivity = false;
            
   TdConnection cn = new  TdConnection(connectionString);
            	
   try
   {
      await cn.OpenAsync();
      connectivity = true;
   }
   catch(Exception)
   {
      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
Overload List