Send feedback on this topic.
Teradata.Client.Provider
State Property
Example 



Teradata.Client.Provider Namespace > TdConnection Class : State Property
Gets the current state of the data source connection.
Syntax
'Declaration
 
Public Overrides NotOverridable ReadOnly Property State As ConnectionState
'Usage
 
Dim instance As TdConnection
Dim value As ConnectionState
 
value = instance.State
public override ConnectionState State {get;}
public:
property ConnectionState State {
   ConnectionState get() override;
}

Property Value

One of the System.Data.ConnectionState enumeration values.
Remarks

The following states are supported:

State Description
Closed

The connection to the data source is closed.

Open

The connection to the data source is open.

Broken

The connection to the data source is broken. This state may occur only after the connection has been opened. The connection must be closed first before attempting to reopen the connection.

Connecting

1. The connection to the data source is reconnecting. This occurrs only after the connection has been opened and lost due to a database or network error.

2. An asynchronous Open is in progress.

The connection state change occurs during the following conditions:

  1. When TdConnection is first created, the state is set to Closed.
  2. When a connection is opened synchronously the state will transition from Closed to Open, generating a TdConnection.StateChange event.
  3. When a connection is opened asynchronously the state will initially transition from Closed to Connecting. After a sussessful connection it will then transition to Open. If the connection fails it will instead transition back to Closed. A StateChange event will be generated for each transition.
  4. The state will transition from Open to Broken when a data source connection encounters an error, generating a StateChange event.
  5. The state will transition from Open to Closed, generating a StateChange event during connection closure.
  6. The state will transition from Open to Connecting, generating a StateChange event during reconnection.
  7. The state will transition from Connecting to Open after a successful reconnection, generating a StateChange event.
  8. The state will transition from Connecting to Closed if the reconnection is cancelled, generating a StateChange event.
  9. The state will transition from Connecting to Broken after a reconnection failure, generating a StateChange event.
Example
The following example creates an instance of TdConnection class, sets the TdConnection.ConnectionString property and opens a connection to the Teradata Database. It later displays the State property.

public TdConnection CreateTdConnection()
{
   TdConnection cn = new TdConnection();
   cn.ConnectionString = “Data Source=Teradata1;User ID=ab;Password=ab;”;
   cn.Open();
   Console.WriteLine(“Connection  is {0}”, cn.State);
   return cn;
}
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