SQLBrowseConnectSQLBrowseConnect

適用於: 是SQL Server 是Azure SQL Database 是Azure Synapse Analytics (SQL DW) 是平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure Synapse Analytics (SQL DW) yesParallel Data Warehouse

SQLBrowseConnect會使用可分類為三種連接資訊層級的關鍵字。SQLBrowseConnect uses keywords that can be categorized into three levels of connection information. 下表針對每個關鍵字指出是否傳回有效值清單以及關鍵字是否為選擇性。For each keyword, the following table indicates whether a list of valid values is returned and whether the keyword is optional.

層級 1Level 1

關鍵字Keyword 傳回清單?List returned? 選擇性?Optional? 描述Description
DSNDSN N/AN/A No SQLDataSources所傳回之資料來源的名稱。Name of the data source returned by SQLDataSources. 如果使用 DRIVER 關鍵字,就無法使用 DSN 關鍵字。The DSN keyword cannot be used if the DRIVER keyword is used.
DRIVERDRIVER N/AN/A No Microsoft® SQL ServerSQL Server Native Client ODBC 驅動程式名稱為 {SQL ServerSQL Server Native Client 11}。Microsoft® SQL ServerSQL Server Native Client ODBC driver name is {SQL ServerSQL Server Native Client 11}. 如果使用 DSN 關鍵字,就無法使用 DRIVER 關鍵字。The DRIVER keyword cannot be used if the DSN keyword is used.

層級 2Level 2

關鍵字Keyword 傳回清單?List returned? 選擇性?Optional? 描述Description
SERVERSERVER Yes No 事件來源所在之網路上的伺服器名稱。Name of the server on the network on which the data source resides. 可以輸入 "(local)" 這個詞彙做為伺服器,在這種情況下可以使用 SQL ServerSQL Server 的本機複本,即使這是非網路的版本。The term "(local)" can be entered as the server, in which case a local copy of SQL ServerSQL Server can be used, even when this is a non-networked version.
UIDUID No Yes 使用者登入識別碼。User login ID.
PWDPWD No 是 (依使用者而定)Yes (depends on the user) 使用者指定的密碼。User-specified password.
APPAPP No Yes 呼叫SQLBrowseConnect的應用程式名稱。Name of the application calling SQLBrowseConnect.
WSIDWSID No Yes 工作站識別碼。Workstation ID. 一般而言,這是應用程式執行所在之電腦的網路名稱。Typically, this is the network name of the computer on which the application runs.

層級 3Level 3

關鍵字Keyword 傳回清單?List returned? 選擇性?Optional? 描述Description
DATABASEDATABASE Yes Yes SQL ServerSQL Server 資料庫的名稱。Name of the SQL ServerSQL Server database.
LANGUAGELANGUAGE Yes Yes SQL ServerSQL Server 所用的國家語言。National language used by SQL ServerSQL Server.

SQLBrowseConnect會忽略儲存在 ODBC 資料來源定義中的資料庫和語言關鍵字的值。SQLBrowseConnect ignores the values of the DATABASE and LANGUAGE keywords stored in the ODBC data source definitions. 如果傳遞至SQLBrowseConnect的連接字串中指定的資料庫或語言無效,則SQLBrowseConnect會傳回 SQL_NEED_DATA 和層級3連接屬性。If the database or language specified in the connection string passed to SQLBrowseConnect is invalid, SQLBrowseConnect returns SQL_NEED_DATA and the level 3 connection attributes.

下列屬性是藉由呼叫SQLSetConnectAttr來設定,可判斷SQLBrowseConnect所傳回的結果集。The following attributes, which are set by calling SQLSetConnectAttr, determine the result set returned by SQLBrowseConnect.

AttributeAttribute 描述Description
SQL_COPT_SS_BROWSE_CONNECTSQL_COPT_SS_BROWSE_CONNECT 如果設定為 SQL_MORE_INFO_YES, SQLBrowseConnect會傳回伺服器屬性的擴充字串。If it is set to SQL_MORE_INFO_YES, SQLBrowseConnect returns an extended string of server properties.

以下是SQLBrowseConnect所傳回之擴充字串的範例:The following is an example of an extended string returned by SQLBrowseConnect:



ServerName\InstanceName;Clustered:No;Version:8.00.131



在這個字串中,分號是用來區隔伺服器相關資訊的不同部分,In this string, semi-colons separate various pieces of information about the server. 逗號則是用來區隔不同的伺服器執行個體。Use commas to separate different server instances.
SQL_COPT_SS_BROWSE_SERVERSQL_COPT_SS_BROWSE_SERVER 如果指定伺服器名稱, SQLBrowseConnect會傳回指定之伺服器的資訊。If a server name is specified, SQLBrowseConnect will return information for the server specified. 如果 SQL_COPT_SS_BROWSE_SERVER 設定為 Null, SQLBrowseConnect會傳回網域中所有伺服器的資訊。If SQL_COPT_SS_BROWSE_SERVER is set to NULL, SQLBrowseConnect returns information for all servers in the domain.



請注意,由於網路問題, SQLBrowseConnect可能不會收到所有伺服器的及時回應。Note that due to network issues, SQLBrowseConnect might not receive a timely response from all servers. 因此,每個要求所傳回的伺服器清單可能各不相同。Therefore, the list of servers returned can vary for each request.
SQL_COPT_SS_BROWSE_CACHE_DATASQL_COPT_SS_BROWSE_CACHE_DATA 當 SQL_COPT_SS_BROWSE_CACHE_DATA 屬性是設定為 SQL_CACHE_DATA_YES 時,您可以在緩衝區長度不足以容納結果時,以片段的方式提取資料。When the SQL_COPT_SS_BROWSE_CACHE_DATA attribute is set to SQL_CACHE_DATA_YES, you can fetch data in chunks when the buffer length is not large enough to hold the result. 這個長度是在 SQLBrowseConnect 的 BufferLength 引數中指定。This length is specified in the BufferLength argument to SQLBrowseConnect.

當有更多資料可用時,會傳回 SQL_NEED_DATA。SQL_NEED_DATA is returned when more data is available. 當沒有其他要擷取的資料時,會傳回 SQL_SUCCESS。SQL_SUCCESS is returned when there is no more data to retrieve.

預設為 SQL_CACHE_DATA_NO。The default is SQL_CACHE_DATA_NO.

高可用性/災害復原的 SQLBrowseConnect 支援SQLBrowseConnect Support for High Availability, Disaster Recovery

如需使用SQLBrowseConnect連線到 AlwaysOn 可用性群組Always On availability groups 叢集的詳細資訊,請參閱高可用性和嚴重損壞修復的 SQL Server Native Client 支援For more information on using SQLBrowseConnect to connect to an AlwaysOn 可用性群組Always On availability groups cluster, see SQL Server Native Client Support for High Availability, Disaster Recovery.

服務主要名稱 (SPN) 的 SQLBrowseConnect 支援SQLBrowseConnect Support for Service Principal Names (SPNs)

開啟連接時,SQL ServerSQL Server Native Client 會將 SQL_COPT_SS_MUTUALLY_AUTHENTICATED 和 SQL_COPT_SS_INTEGRATED_AUTHENTICATION_METHOD 設定為開啟連接所使用的驗證方法。When a connection is opened, SQL ServerSQL Server Native Client sets SQL_COPT_SS_MUTUALLY_AUTHENTICATED and SQL_COPT_SS_INTEGRATED_AUTHENTICATION_METHOD to the authentication method used to open the connection.

如需 Spn 的詳細資訊,請參閱客戶(端)連接( )ODBC 中的服務主體名稱 spnFor more information about SPNs, see Service Principal Names (SPNs) in Client Connections (ODBC).

變更記錄Change History

更新的內容Updated content
已記載 SQL_COPT_SS_BROWSE_CACHE_DATA。Documented SQL_COPT_SS_BROWSE_CACHE_DATA.

另請參閱See Also

SQLBrowseConnect 函數 SQLBrowseConnect Function
ODBC API 實作詳細資料ODBC API Implementation Details