Format description of the ConnectionString string for the C # connection database

Source: Internet
Author: User
Tags connection pooling failover sql server express

The basic format of the connection string includes a series of keyword/value pairs separated by semicolons. The equal sign (=) joins each keyword and its value. To include a value that contains a semicolon, single quote character, or double quote character, the value must be enclosed in double quotes. If the value contains both semicolons and double quote characters, the value can be enclosed in single quotes. If the value starts with a double quote character, you can also use single quotes. Conversely, you can use double quotes if the value starts with a single quotation mark. If the value contains both single and double quote characters, the quote character that is used to enclose the value must appear in pairs each time it appears.

To include leading or trailing spaces in a string value, the value must be enclosed in single or double quotes. Even if you enclose an integer, Boolean, or enumeration value in quotation marks, any leading or trailing spaces around it are ignored. However, the space within the string keyword or value is preserved. When you use the. NET Framework version 1.1 or later, you can use either single or double quotes in the connection string, instead of using delimiters (for example, data source= my ' server or data source= my "server), However, the quote character cannot be the first or last character of the value.

To include an equal sign (=) in a keyword or value, it must have another equal sign before it. For example, in a hypothetical connection string,

Copy Code
"Key==word=value"

The keyword is "Key=word" and the value is "value".

If a specific keyword in a keyword/value pair appears multiple times in the connection string, the last one listed is used for the value set.

Keywords are not case-sensitive.

The following table lists the valid names for the keyword values in ConnectionString.

The name of the workstation to which

Key words

Default value

Description

Application Name

N/A

The name of the application, or ". Net SqlClient Data Provider" (if no application name is provided).

Async

' False '

If set to true, asynchronous operation support is enabled. The recognizable values are true, false, yes, and No.

AttachDbFileName

Or

Extended Properties

Or

Initial File Name

N/A

The name of the primary database file, including the full pathname of the database that can be connected. Only master data files with the. mdf extension support AttachDbFileName.

If the primary data file is read-only, the attach operation will fail.

The path can be either an absolute or a relative path, depending on whether or not you use DataDirectory to replace the string. If you use DataDirectory, the corresponding database file must exist in the subdirectory of the directory that the replacement string points to.

Attention:

Remote servers, HTTP, and UNC path names are not supported.

You must specify the database name by using the keyword "database" (or one of its aliases) as follows:

"Attachdbfilename=| datadirectory|/data/yourdb.mdf;integrated Security=true;database=yourdatabase "

If there is a log file in the directory where the data file resides and the "database" keyword is used when attaching the master data file, an error is generated. In this case, remove the log file. After the database is attached, a new log file is automatically generated based on the physical path.

Connect Timeout

Or

Connection Timeout

15

The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error.

Context Connection

' False '

True if an in-process connection should be made to SQL Server.

Current Language

N/A

SQL Server language record name.

Data Source

Or

Server

Or

Address

Or

Addr

Or

Network address

N/A

The name or network address of the instance of SQL Server to which you want to connect. You can specify the port number after the server name:

Server=tcp:servername, PortNumber

Always use (local) when specifying a native instance. To enforce the use of a protocol, add one of the following prefixes:

NP: (local), TCP: (local), LPC: (local)

Attention:

Ado.net 2.0 does not support the execution of asynchronous commands on SQL Server 2000 or later shared memory. However, you can force TCP to replace shared memory by adding a "TCP:" prefix to the server name in the connection string, or by using localhost.

Encrypt

' False '

When this value is true, if the server side has a certificate installed, SQL Server uses SSL encryption for all data that is transferred between the client and the server. The recognizable values are true, false, yes, and No.

Enlist

' False '

True indicates that the SQL Server connection pooling program automatically enlists the connection in the current transaction context of the creation thread.

Failover Partner

N/A

The name of the failover partner server in which to configure database mirroring.

The. NET Framework version 1.0 or 1.1 does not support the Failover Partner keyword.

Initial Catalog

Or

Database

N/A

The name of the database.

Integrated security

Or

Trusted_Connection

' False '

When false, the user ID and password are specified in the connection. When True, authentication is performed using the current Windows account credentials.

The recognized value is true, false, yes, no, and SSPI (strongly recommended) equivalent to True.

Multipleactiveresultsets

' False '

If true, the application can maintain multiple active result sets (MARS). If False, the application must process or cancel multiple result sets in one batch before executing any other batches on the connection.

The recognizable value is true and false.

The. NET Framework version 1.0 or 1.1 does not support this keyword.

Network Library

Or

Net

' DBMSSOCN '

A network library that is used to establish a connection to an instance of SQL Server. Supported values include DBNMPNTW (Named Pipes), DBMSRPCN (Multiprotocol), Dbmsadsn (Apple Talk), Dbmsgnet (VIA), DBMSLPCN (Shared memory) and DBMSSPXN (ipx/spx) and DBMSSOCN (TCP/IP).

The corresponding network DLL must be installed on the system to which you want to connect. If you do not specify a network, use a local server (such as "." or "(local)"), the shared memory is used.

Packet Size

8192

The size, in bytes, of the network packet used to communicate with an instance of SQL Server.

Password

Or

Pwd

N/A

The password for the SQL Server account login. Recommended not to use. To maintain a high level of security, we strongly recommend that you use the integrated or trusted_connection keyword.

Persist Security Info

' False '

When the value is set to False or no (strongly recommended), security-sensitive information, such as a password, will not be returned as part of the connection if the connection is open or is always open. Resetting the connection string resets all connection string values, including passwords. The recognizable values are true, false, yes, and No.

Replication

' False '

True if a connection is used to support replication.

Transaction Binding

Implicit Unbind

Controls the connection associated with a registered System.Transactions transaction.

Possible values include the following:

Transaction binding=implicit Unbind;

Transaction binding=explicit Unbind;

Implicit Unbind enables the connection to detach from the transaction at the end of the transaction. After separation, other requests on the connection are executed in autocommit mode. The System.Transactions.Transaction.Current property is not checked when the request is executed while the transaction is active. When the transaction ends, other requests are executed in autocommit mode.

Explicit Unbind allows the connection to remain connected to the transaction until the connection is closed or an explicit sqlconnection.transactionenlist (null) is invoked. If Transaction.Current is not a registered transaction or a registered transaction is not active, a InvalidOperationException is thrown.

TrustServerCertificate

' false '

If set to true, use SSL to encrypt the channel, but not through the certificate chain pair to Reliability is validated. If you set TrustServerCertificate to True and set Encrypt to False, the channel is not encrypted. The recognizable values are true, false, yes, and No. For more information, see "Encryption Hierarchy" (encryption hierarchy) and "Using encryption without in SQL Server book online (SQL Server 2005 Books Online) Validation "(using unauthenticated encryption).

Type System Version

N/A

A string value indicating the type system expected by the application. Possible values include the following:

Type System version=sql Server 2000;

Type System version=sql Server 2005;

Type System version=sql Server 2008;

Type System version=latest;

If set to SQL Server 2000, the SQL Server 2000 type system will be used. When connecting to an instance of SQL Server 2005, perform the following transformations:

XML to NTEXT

UDT to VARBINARY

VARCHAR (max), NVARCHAR (max), and VARBINARY (max) are respectively to TEXT, NEXT, and IMAGE.

If set to SQL Server 2005, the SQL Server 2005 type system will be used. No conversions are made to the current version of Ado.net.

If set to Latest, this client-server pair will be used for the latest version that cannot be processed. This latest version will be updated automatically as the client and server components are upgraded.

User ID

N/A

SQL Server login account. Recommended not to use. To maintain a high level of security, we strongly recommend that you use the integrated or trusted_connection keyword.

User Instance

' False '

A value that indicates whether to redirect the connection from the default SQL Server Express instance to a runtime-initiated instance running under the caller account.

Workstation ID

Local computer name

Connect to SQL Server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.