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



Teradata.Client.Provider Namespace : TdQueryBand Class
TdQueryBand manages Teradata Query Bands for an application. It enables an application to create, modify, and remove Query Bands. Query Bands that are managed by TdQueryBand can be applied to a Connection or Transaction by calling TdConnection.ChangeQueryBand or TdTransaction.ChangeQueryBand, respectively.
Syntax
'Usage
 
Dim instance As TdQueryBand
Remarks

The Teradata Vantage Advanced SQL Engine supports Query Bands beginning with the 12.0 release. If an attempt is made to use Query Bands when connected to a version of the SQL Engine that is prior to 12.0, a TdException will be thrown.

Some of the uses for Query Bands are to enhance security (Trusted Session), enable job control, and to perform audits. Query Bands will also allow administrators to better analyze the use of their Advanced SQL Engine. For more information refer to Query Banding and Trusted Sessions and the Teradata Manual: SQL Data Definition Language Detailed Topics.

A Trusted Session is defined using Query Bands. To define a Trusted Session the reserved Query Band keys ProxyUser and/or ProxyRole are defined. The values assigned to the ProxyUser and/or ProxyRole have corresponding access rights in the SQL Engine. When an application connects to a SQL Engine, the user of the application is limited to only those rights granted to the ProxyUser and/or ProxyRole.

Trusted Sessions are supported by the Advanced SQL Engine version 13.0 or greater. A TdException will get thrown indicating that Trusted Sessions are not supported under the following conditions:

The TdQueryBand class enables an application to define Query Bands that can be applied at the Connection or Transaction level. Query Bands are defined as key=value pairs. When a Query Band is represented as a string it will appear as:

"ProxyUser = user1; ApplicationName = app1; Group = group1;"

For more information on Connection and Transaction level Query Bands refer to the Connection Level Query Bands and Transaction Level Query Bands sections of the Developer's Guide.

If the TdQueryBand class is to be used, an application must not execute SET QUERY_BAND statements. The provider will manage the creation and deletion of Query Bands.

If connection pooling has been enabled, the Query Bands will be removed from the connection when TdConnection.Close has been called. The Query Bands that were specified in the connection string will be re-applied to the connection when it is fetched from the pool by TdConnection.Open.

The TdConnectionStringBuilder.QueryBand connection string attribute does not affect the association of the Connection String with a Connection Pool. Refer to Connection Pooling for more information.

Example

The following is an example of a method that defines Query Bands at the Connection and Transaction level.

static public void QueryBandExample()
{
   TdConnection conn = new TdConnection(
          @"DataSource=teradata1;UserId=user1;Password=password1;QueryBand='ProxyUser=user1;ApplicationName=app1;'");
          
   // The Query Bands specified using the QueryBand connection string attribute
   // are defined at the Connection level.
   conn.Open();
   
   // Retrieving the Query Bands from the connection
   TdQueryBand qb = conn.QueryBand;
   
   // Adding a new Query Band to the connection.
   // This is a custom Query Band only used by the application.
   qb["CustomBand"] = "custom1";
   
   // After the TdQueryBand instance has been modified it needs to be
   // applied by the connection
   conn.ChangeQueryBands(qb);
   
   //
   // The method performs required tasks
   //
   
   // Defining Query Bands that will be used in a transaction
   TdQueryBand transQB = new TdQueryBand("Group=group1");
   
   // Overwriting the ApplicationName that was defined at the Connection level
   transQB["ApplicationName"] = "newName";
   
   // Starting a transaction
   TdTransaction trans = conn.BeginTransaction(transQb);
   
   // Query Bands defined at the Connection level are also valid
   // in the transaction.
   
   // Adding additional transaction level Query Bands by using the Add method
   //
   // After the transaction is started, it is recommended that the Query Bands
   // be retrieved from the TdTransaction.QueryBand property if changes are to
   // be made.
   transQB = trans.QueryBand;
   
   transQB.Add("JobId", "123");
   transQB.Add("JobGroup", "appGroup1");
   
   // After changes are made, the Query Band must be applied to the Transaction.
   trans.ChangeQueryBand(transQB);
   
   //
   // The method performs required tasks
   //
   
   // After the transaction is closed, the Query Bands defined at the Transaction
   // level no longer exist.  The connection level Query Bands are still valid.
   // Any Query Bands that were re-defined at the Transaction level are restored
   // to their values defined at the Connection level.
   trans.Commit();
   
   //
   // Method performs required tasks
   //
   
   conn.Close();
}
Inheritance Hierarchy

System.Object
   Teradata.Client.Provider.TdQueryBand

Requirements

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

See Also

Reference

TdQueryBand Members
Teradata.Client.Provider Namespace
Query Banding and Trusted Sessions
Connection Pooling
QueryBand Property
ChangeQueryBand Method
QueryBand Property
ChangeQueryBand Method
QueryBand Property