ConnectionString Property
Syntax:
public string ConnectionString { get; set; }
Description:
Type: System.String
Gets or sets the connection string. A connection string provides information on how to access the database as well as connection parameters. The string is made up of key, value pairs separated by semicolons; i.e. "<key>=<value>;[<key>=<value>…]
". The following keys are recognized.
Key(s) | Value | Comments | ||||||
---|---|---|---|---|---|---|---|---|
Host Hostname Host Name |
local <hostname> |
Required argument. If ‘local' is specified the connection will go directly to the database (via Platform Invoke). If a hostname is specified, that host will be used to communicate with the database. | ||||||
Port | <number> | Port number for TCP/IP connections to the database. Default 21553 + 2. | ||||||
tfs type | <type> |
Specify the TFS type to use:
|
||||||
Database | <name> | Optional database name to be opened automatically when the connection is established. | ||||||
AutoCommit Auto Commit |
true|false on|off 1|0 |
Optional setting to specify whether auto commit is enabled for the connection. | ||||||
OpenMode Open Mode |
s x n r |
Optional open mode for the databases for the connection. Options are "s" for shared mode, "x" for exclusive mode, "n" for exclusive, no-transaction mode, and "r" for read-only mode. The default is "s" (shared mode). | ||||||
DateFormat Date Format |
YYYYMMDD MMDDYYYY DDMMYYYY |
Optional specification for the date format that the SQL engine will default to. The default is YYYYMMDD. | ||||||
DateSeparator Date Separator DateSep |
/ - |
Optional specification for the separator to be used between the month, day, and year portions of dates. The default is "-". | ||||||
LockTimeout Lock Timeout Timeout |
<number> | Optional setting for the timeout on lock requests in seconds. The default is 10 seconds. | ||||||
Read Only Transactions Read Only Trmode |
true|false on|off 1|0 |
Optional setting to indicate that the SQL engine should use read-only transactions by default for reading data. The default is off. |
The connection string cannot be changed while the connection is open.
Exceptions:
Exception | Condition |
---|---|
ArgumentException | One or more parts do not follow the <key>=<value> format. |
ArgumentException | The key specified is not recognized. |
ArgumentException | The value is not appropriate for the specified key. |
OverflowException | The value was expected to be a number but was too large or small for an Int32. |
FormatException | The value was expected to be numeric but was not a valid number |
Reference:
For more information, reference MSDN documentation for: System.Data.Common.DbConnection.ConnectionString