Gets or sets the string that is used to open a database connection.
[Visual Basic]
Public Property ConnectionString As String Implements _
IDbConnection.ConnectionString
[C#]
public string ConnectionString {get; set;}
[C++]
public: __property String* get_ConnectionString();
public: __property void set_ConnectionString(String*);
[JScript]
public function get ConnectionString() : String;
public function set ConnectionString(String);
The connection string that includes settings, such as the database name, that are needed to establish an initial connection. The default value is an empty string (""). The maximum length is 1024 characters.
You can use the ConnectionString property to connect to any supported data server. You can set the ConnectionString property only when the connection is closed.
The supported keywords are as follows.
Keyword | Default | Description |
---|---|---|
Database | The database alias (for a cataloged database). The maximum size of the Database keyword is 255 bytes. | |
Password | PWD | The password. | |
Server | The server name with an optional port number for a direct connection. Use either the IPv4 notation (server name|ip address[:port]) or the IPv6 notation. | |
User ID | UID | The user ID. | |
NewPWD | The new password for the user name. |
Keyword | Default | Description |
---|---|---|
allowDynamicSQL | Specifies whether to allow an application to run dynamically any SQL statements that are not captured in a pureQueryXML file or that are captured but not bound. | |
captureMode | off | An indication of whether dynamically
executed statements are captured for use with pureQuery®. The following values are acceptable:
|
capturedOnly | Specifies whether to run only the SQL statements that are in the pureQueryXML file. | |
enableDynamicSQLReplacement | Specifies whether to run alternative SQL statements that were added to a pureQueryXML file and both the original statements and the alternative statements were not bound. | |
executionMode | dynamic | An indication of whether previously captured
statements are executed statically by using pureQuery technology. The following values
are acceptable:
|
maxNonParmSQL | Specifies the maximum number of non-parameterized SQL statements to capture. This option applies only when the value of captureMode is ON. When captureMode is OFF, pureQuery ignores this parameter. | |
propertiesGroupId | Specifies a runtime group ID in a repository that is created in a database. | |
pureQueryXML | The file name and path of the pureQuery capture file. | |
pureQueryXmlRepository | Specifies the repository that contains the pureQueryXML file data that is used with a .NET application enabled with pureQuery client optimization. | |
repositoryRequired | Specifies the pureQuery client optimization behavior if errors occur during retrieving or writing pureQuery data. | |
sqlLiteralSubstitution | Specifies whether to capture and consolidate SQL statements that share syntax but differ only in the literal values by having pureQuery substitute parameter markers for the literal values. | |
traceFile | The name of the pureQuery log file. | |
traceLevel | Specifies the level of detail to write to the log file. |
Keyword | Default | Description |
---|---|---|
Authentication | Not specified | The type of authentication. The following
values are acceptable:
|
ClientAccountingString | The client accounting string that is sent to a database. | |
ClientApplicationName | The client application name that is sent to a database. | |
ClientEncAlg | An indication of whether advanced encryption standard (AES) encryption is being used. The acceptable value is AES. | |
ClientUserID | The client user ID that is sent to a database. | |
ClientWorkStationName | The client workstation name that is sent to a database. | |
CodePage | 0 | The code page identifier. |
ConcurrentAccessResolution | The string values that represent the
concurrent access resolution. The following values are acceptable:
The database server defines the default behavior if the client does not provide a ConcurrentAccessResolution value. |
|
ConnectNodeNumber | 0 to 999 | Specifies the database partition server to which a connection is to be made. |
Connection Lifetime | 60 | The amount of time in seconds that a connection can remain idle in the connection pool. |
Connection Reset | false | An indication of whether a connection
is put into the connection pool when the connection is closed. The
following values are acceptable:
|
Connection Timeout | Connect Timeout | Timeout | 0 | The time in seconds to wait for a database
connection to be established. A value of 0 indicates
that there is no time limit for a database connection to be established. If
client reroute is enabled, the maximum waiting time is approximately
double that of the specified connect timeout because there is a second
connection attempt to the alternate server. The connect timeout value is enforced for a connection regardless of a high availability solution being enabled. If a connection attempt fails within the time specified by the connect timeout value, control is returned to the application with an SQL30081N error. The error and control is returned whether all alternative servers are tried or not. |
CurrentPackageSet | Issues the SET CURRENT PACKAGESET statement after every connection. | |
CurrentSchema | The schema name that is used to qualify all unqualified SQL objects that are used with the current connection. | |
CurrentSQLID | The SQLID that is used to qualify all unqualified SQL objects that are used with the current connection to DB2 for z/OS. On servers other than DB2 for z/OS, setting the CurrentSQLID keyword is equivalent to setting the CurrentSchema keyword. | |
DB2Explain | off | Determines whether Explain snapshot,
Explain table, or both information will be generated by the server.
The following values are acceptable:
|
DBName | This option is used only when connecting to DB2 for z/OS and OS/390®, and only if (base) table catalog information is requested by the application. If many tables exist in the z/OS or OS/390 subsystem, you can specify a DBName to reduce the time it takes for the application to query table information, and reduce the amount of table information in the result set. | |
DelimIdent | This option is used only when connecting
to the Informix® database
server.
The DelimIdent parameter specifies whether the
connected Informix database
server must
support delimited SQL identifiers. Valid value for the DelimIdent parameter
includes:
|
|
DisableCursorHold | false | An indication of whether
cursors that are opened on the server should be left open after committing
a transaction. The following values are acceptable:
|
Enlist | true | An indication of whether enlistment in
the Distributed Transaction Coordinator (DTC) is allowed. The following
values are acceptable:
|
FitHighPrecisionType | ReturnException | The following values are acceptable:
|
HostVarParameter | false | An indication of whether host variable
(:param) support is enabled. The following values are acceptable:
|
Interrupt | 1 | An interrupt processing mode. The following
values are acceptable:
|
Isolation Level | IsolationLevel | The isolation level for the connection.
The following values are acceptable:
Note: The keyword Chaos is supported only for
applications that are connected to the IBM® iSeries® servers.
If you set the isolation level to Transaction, the isolation level is set to the value of Transaction.Current.IsolationLevel. |
|
Max Pool Size | No maximum | The maximum pool size. |
Min Pool Size | 0 | The minimum pool size. |
Persist Security Info | false | An indication of whether security-sensitive
information is returned. The following values are acceptable:
|
Pooling | true | An indication of whether connection pooling
is disabled. The following values are acceptable:
|
ProgramId | The program ID that is sent to a database. | |
ProgramName | The program name that is sent to a database. | |
QueryTimeout | Gets or sets the value of the QueryTimeout keyword. The QueryTimeout indicates the default number of seconds to wait for an SQL statement or XQuery expression to complete executing before attempting to cancel the execution and return control to the application. This attribute overrides the default 30 second DB2Command.CommandTimeout value. | |
ResultArrayAsReturnValue | false | An indication of whether results sets
from Informix user-defined
routines (UDRs) are returned as parameters of type ReturnValue. If you set the ResultArrayAsReturnValue keyword to true, result sets are returned as parameters of ReturnValue. This keyword is ignored when a ReturnValue parameter is not bound in the parameter collection. |
RetrieveXMLInBinaryFormat | false | The value that represents whether XML data should be returned in binary format. |
RetryParameterBindingOnError | true | The value that indicates whether the provider re-executes failed statements. |
SchemaList | The schema list that is used to provide a more restrictive default, and therefore improve performance, for those applications that list every table in the database. | |
Security | An indication of whether to use SSL as a secure transport. | |
SessionTimeZone | Sets the value of the SESSION TIMEZONE special register on the z/OS server. | |
SSLClientKeystash | Set SSLClientKeystash to the fully qualified stash file name. | |
SSLClientKeystoredb | Set SSLClientKeystoredb to the fully qualified key database file name. | |
SSLClientKeystoreDBPassword | Sets keystore database password to use with the CERTIFICATE authentication. | |
SSLClientLabel | Sets a unique label, which is mapped to a specific certificate to use with the CERTIFICATE authentication. | |
StatementConcentrator | An indication of whether statement
concentration is used. The following values are acceptable:
|
|
SkipSynonymProcessing | false | An indication of whether IBM Data Server Provider for .NET can send a
connection string to the DbPermission.Add method without passing through
the DB2ConnectionStringBuilder class. The following
values are acceptable:
|
TargetPrincipal | The fully qualified Kerberos principal name for the target server; that is, the fully qualified Kerberos principal of the DB2 instance owner in the form of name/instance@REALM. For Windows operating systems, the fully qualified Kerberos principal name is the logon account of the DB2 server service in the form of userid@DOMAIN, userid@xxx.xxx.xxx.com or domain\userid |
|
TrustedContextSystemUserID | TCSUID | The trusted context SYSTEM AUTHID that is to be used with the connection. |
|
TrustedContextSystemPassword | TCSPWD | The password that corresponds to the trusted context SYSTEM AUTHID to be used with the connection. |
Many of the settings that you can specify in the string have corresponding read-only properties, for example, the DATABASE corresponds to the Database property. When you set the connection string, all of these read-only properties are updated, except if an error is detected. In this case, none of the properties are updated. DB2Connection properties, such as Database) return only default settings or those settings that you specified for the ConnectionString property.
Validation of the connection string occurs when you set it.
Resetting the ConnectionString property on a closed connection resets all connection string values and related properties, including the password.
[Visual Basic, C#] The following examples create an DB2Connection and set some of its properties in the connection string:
[Visual Basic]
Public Sub CreateDB2Connection()
Dim myConnString As String = _
"DATABASE=SAMPLE;"
Dim myConnection As New DB2Connection(myConnString)
myConnection.Open()
MessageBox.Show("ServerVersion: " + myConnection.ServerVersion _
+ ControlChars.Cr + "Database: " + myConnection.Database.ToString())
myConnection.Close()
End Sub
[C#]
public void CreateDB2Connection()
{
string myConnString = "DATABASE=SAMPLE;";
DB2Connection myConnection = new DB2Connection(myConnString);
myConnection.Open();
MessageBox.Show("ServerVersion: " + myConnection.ServerVersion
+ "\nDatabase: " + myConnection.Database.ToString());
myConnection.Close();
}