sqlserver資料庫連接字串全解

來源:互聯網
上載者:User

      今天在webcasts上看sql server 2008的新功能介紹,無意中發現在串連sql server 資料庫時,還有一個 

Failover Partner的選項。以前都沒注意過,它的主要功能就是在使用DB Mirror時,讓應用程式可以自己在principal和secondary之間,選擇一個可用的串連,不用再手動切換了。以前還真沒注意過個串連配置。例如連接字串為:

Data Source=DataBaseStr1;Failover Partner=DataBaseStr2;Initial Catalog=MirrorTestDB;User ID=sa;Password=sa

那麼程式會自動連接DataBaseStr1,當DataBaseStr1這個資料庫Fail Over時,就自動選擇串連 DataBaseStr2。

 

     這個選項在2005時特別有用,但是要注意,在2008中,FailOver這個選項已經沒用了。因為2008已經具備自動檢測的功能了,在2008中,直接寫成:Data Source=DataBaseStr1;Initial Catalog=MirrorTestDB;User ID=sa;Password=sa就可以了,當DataBaseStr1 FailOver時,資料庫會自動為你切換的

 

下面列出了msdn中關於資料庫連接字串的具體使用方法,以作備份。

Keyword

Default

Description

Application Name

N/A

The name of the application, or '.NET SQLClient Data Provider' if no application name is provided.

Async

'false'

When true, enables asynchronous operation support. Recognized 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 path name of an attachable database. AttachDBFilename is only supported for primary data files with an .mdf extension.

The attachment will fail if the primary data file is read-only.

The path may be absolute or relative by using the DataDirectory substitution string. If DataDirectory is used, the database file must exist within a subdirectory of the directory pointed to by the substitution string.

Note:

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

The database name must be specified with the keyword 'database' (or one of its aliases) as in the following:

"AttachDbFileName=|DataDirectory|/data/YourDB.mdf;integrated security=true;database=YourDatabase"

An error will be generated if a log file exists in the same directory as the data file and the 'database' keyword is used when attaching the primary data file. In this case, remove the log file. Once the database is attached, a new log file will be 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 to SQL Server should be made.

Current Language

N/A

The 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 to connect. The port number can be specified after the server name:

server=tcp:servername, portnumber

When specifying a local instance, always use (local). To force a protocol, add one of the following prefixes:

np:(local), tcp:(local), lpc:(local)

Note:

ADO.NET 2.0 does not support asynchronous commands over shared memory for SQL Server 2000 or earlier. However, you can force the use of TCP instead of shared memory, either by prefixing tcp: to the server name in the connection string, or by using localhost.

Encrypt

'false'

When true, SQL Server uses SSL encryption for all data sent between the client and server if the server has a certificate installed. Recognized values are true, false, yes, and no.

Enlist

'false'

true indicates that the SQL Server connection pooler automatically enlists the connection in the creation thread's current transaction context.

Failover Partner

N/A

The name of the failover partner server where database mirroring is configured.

The Failover Partner keyword is not supported by .NET Framework version 1.0 or 1.1.

Initial Catalog

-or-

Database

N/A

The name of the database.

Integrated Security

-or-

Trusted_Connection

'false'

When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication.

Recognized values are true, false, yes, no, and sspi (strongly recommended), which is equivalent to true.

MultipleActiveResultSets

'false'

When true, an application can maintain multiple active result sets (MARS). When false, an application must process or cancel all result sets from one batch before it can execute any other batch on that connection.

Recognized values are true and false.

The keyword is not supported by .NET Framework version 1.0 or 1.1.

Network Library

-or-

Net

'dbmssocn'

The network library 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 connect. If you do not specify a network and you use a local server (for example, "." or "(local)"), shared memory is used.

Packet Size

8192

Size in bytes of the network packets used to communicate with an instance of SQL Server.

Password

-or-

Pwd

N/A

The password for the SQL Server account logging on. Not recommended. To maintain a high level of security, we strongly recommend that you use the Integrated Security or Trusted_Connection keyword instead.

Persist Security Info

'false'

When set to false or no (strongly recommended), security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state. Resetting the connection string resets all connection string values including the password. Recognized values are true, false, yes, and no.

Replication

'false'

true if replication is supported using the connection.

Transaction Binding

Implicit Unbind

Controls connection association with an enlisted System.Transactions transaction.

Possible values are:

Transaction Binding=Implicit Unbind;

Transaction Binding=Explicit Unbind;

Implicit Unbind causes the connection to detach from the transaction when it ends. After detaching, additional requests on the connection are performed in autocommit mode. The System.Transactions.Transaction.Current property is not checked when executing requests while the transaction is active. After the transaction has ended, additional requests are performed in autocommit mode.

Explicit Unbind causes the connection to remain attached to the transaction until the connection is closed or an explicit SqlConnection.TransactionEnlist(null) is called. An InvalidOperationException is thrown if Transaction.Current is not the enlisted transaction or if the enlisted transaction is not active.

TrustServerCertificate

'false'

When set to true, SSL is used to encrypt the channel when bypassing walking the certificate chain to validate trust. If TrustServerCertificate is set to true and Encrypt is set to false, the channel is not encrypted. Recognized values are true, false, yes, and no. For more information, see "Encryption Hierarchy" and "Using Encryption Without Validation" in SQL Server 2005 Books Online.

Type System Version

N/A

A string value that indicates the type system the application expects. Possible values are:

Type System Version=SQL Server 2000;

Type System Version=SQL Server 2005;

Type System Version=SQL Server 2008;

Type System Version=Latest;

When set to SQL Server 2000, the SQL Server 2000 type system is used. The following conversions are performed when connecting to a SQL Server 2005 instance:

XML to NTEXT

UDT to VARBINARY

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

When set to SQL Server 2005, the SQL Server 2005 type system is used. No conversions are made for the current version of ADO.NET.

When set to Latest, the latest version than this client-server pair can handle is used. This will automatically move forward as the client and server components are upgraded.

User ID

N/A

The SQL Server login account. Not recommended. To maintain a high level of security, we strongly recommend that you use the Integrated Security or Trusted_Connection keywords instead.

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 account of the caller.

Workstation ID

The local computer name

The name of the workstation connecting to SQL Server.

 

 

Name

Default

Description

Connection Lifetime

0

When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified by Connection Lifetime. This is useful in clustered configurations to force load balancing between a running server and a server just brought online.

A value of zero (0) causes pooled connections to have the maximum connection timeout.

Connection Reset

'true'

Determines whether the database connection is reset when being drawn from the pool. For SQL Server version 7.0, setting to false avoids making an additional server round trip when obtaining a connection, but you must realize that the connection state, such as database context, is not being reset.

The connection pooler is not influenced by the ChangeDatabase method as long you do not set Connection Reset to false. As the connection comes out of the pool the connection is reset with the server moving back to the login time database. There are no new connections created or reauthentications. If you set Connection Reset to false, connections in the pool to different databases might result.

Enlist

'true'

When true, the pooler automatically enlists the connection in the creation thread's current transaction context. Recognized values are true, false, yes, and no.

Load Balance Timeout

0

The minimum time, in seconds, for the connection to live in the connection pool before being destroyed.

Max Pool Size

100

The maximum number of connections allowed in the pool.

Min Pool Size

0

The minimum number of connections allowed in the pool.

Pooling

'true'

When true, the SQLConnection object is drawn from the appropriate pool, or if it is required, is created and added to the appropriate pool. Recognized values are true, false, yes, and no.

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.