ConnectionString 屬性 (ADO)ConnectionString Property (ADO)

表示用來建立資料來源連接的資訊。Indicates the information used to establish a connection to a data source.

設定和傳回值Settings and Return Values

設定或傳回 字串 值。Sets or returns a String value.

備註Remarks

您可以使用 ConnectionString 屬性來指定資料來源,方法是傳遞包含一連串 引數 = value 語句的詳細連接字串(以分號分隔)。Use the ConnectionString property to specify a data source by passing a detailed connection string containing a series of argument = value statements separated by semicolons.

ADO 支援 ConnectionString 屬性的五個引數;任何其他引數都會直接傳遞給提供者,而不會由 ADO 處理。ADO supports five arguments for the ConnectionString property; any other arguments pass directly to the provider without any processing by ADO. ADO 支援的引數如下所示。The arguments ADO supports are as follows.

引數Argument 描述Description
提供者 =Provider= 指定連接所要使用之提供者的名稱。Specifies the name of a provider to use for the connection.
檔案名 =File Name= 指定提供者特定檔案的名稱 (例如,保存的資料來源物件) 包含預設的連接資訊。Specifies the name of a provider-specific file (for example, a persisted data source object) containing preset connection information.
遠端提供者 =Remote Provider= 指定開啟用戶端連接時要使用的提供者名稱。Specifies the name of a provider to use when opening a client-side connection. (僅限遠端資料服務。 ) (Remote Data Service only.)
遠端伺服器 =Remote Server= 指定開啟用戶端連接時要使用之伺服器的路徑名稱。Specifies the path name of the server to use when opening a client-side connection. (僅限遠端資料服務。 ) (Remote Data Service only.)
URL =URL= 將連接字串指定為識別資源的絕對 URL,例如檔案或目錄。Specifies the connection string as an absolute URL identifying a resource, such as a file or directory.

設定 ConnectionString 屬性並開啟 連接 物件之後,提供者可以改變屬性的內容,例如,將 ADO 定義的引數名稱對應至特定提供者的對等專案。After you set the ConnectionString property and open the Connection object, the provider may alter the contents of the property, for example, by mapping the ADO-defined argument names to their equivalents for the specific provider.

Connectionstring屬性會自動繼承Open方法的ConnectionString引數所使用的值,因此您可以在open方法呼叫期間覆寫目前的ConnectionString屬性。The ConnectionString property automatically inherits the value used for the ConnectionString argument of the Open method, so you can override the current ConnectionString property during the Open method call.

因為 檔案名 引數會導致 ADO 載入關聯的提供者,所以您無法同時傳遞 提供者檔案名 引數。Because the File Name argument causes ADO to load the associated provider, you cannot pass both the Provider and File Name arguments.

當連線關閉時,會讀取/寫入 ConnectionString 屬性,而當連接開啟時,則為唯讀屬性。The ConnectionString property is read/write when the connection is closed and read-only when it is open.

ConnectionString屬性中的引數重複專案會被忽略。Duplicates of an argument in the ConnectionString property are ignored. 使用任何引數的最後一個實例。The last instance of any argument is used.

注意

遠端資料服務使用量 使用於用戶端 連接 物件時, ConnectionString 屬性只能包含 遠端提供者遠端伺服器 參數。Remote Data Service Usage When used on a client-side Connection object, the ConnectionString property can include only the Remote Provider and Remote Server parameters.

下表列出每個 Windows 作業系統的預設 ADO 提供者:The following table lists the default ADO provider for each Windows operating system:

預設 ADO 提供者Default ADO provider Windows 作業系統Windows operating system
MSDASQLMSDASQL

(若要改善原始程式碼的可讀性,請在連接字串中明確指定提供者名稱。 ) (To improve the readability of source code, explicitly specify the provider name in the connection string.)
Windows 2000 (32 位) Windows 2000 (32-bit)

Windows XP (32 位元)Windows XP (32-bit)

Windows 2003 Server (32 位) Windows 2003 Server (32-bit)

Windows Vista (32 位元)Windows Vista (32-bit)

Windows Vista Service Pack 1 或更新版本 (32 位和64位) Windows Vista Service Pack 1 or later (32-bit and 64-bit)

Windows Vista (32 位和64位) 之後的 windows 版本Windows versions after Windows Vista (32-bit and 64-bit)
沒有預設值。No default.

當 ADO 應用程式在下列作業系統上執行且未明確指定提供者時,ADO 會傳回下列錯誤:「ADODB。連接:未指定提供者,而且沒有指定的預設提供者」When an ADO application runs on the following operating systems and does not specify the provider explicitly, ADO returns the following error: "ADODB.Connection: provider is not specified and there is no designated default provider"
Windows 2000 (64 位) Windows 2000 (64-bit)

Windows XP (64 位元)Windows XP (64-bit)

Windows 2003 Server (64 位) Windows 2003 Server (64-bit)

Windows Vista (64 位元)Windows Vista (64-bit)

套用至Applies To

Connection 物件 (ADO)Connection Object (ADO)

另請參閱See Also

ConnectionString、ConnectionTimeout 和 State 屬性範例 (VB) ConnectionString, ConnectionTimeout, and State Properties Example (VB)
ConnectionString、ConnectionTimeout 和 State 屬性範例 (VC + +) ConnectionString, ConnectionTimeout, and State Properties Example (VC++)
附錄 A:提供者Appendix A: Providers