使用 SQL Server Native Client 標頭檔與程式庫檔案Using the SQL Server Native Client Header and Library Files

適用於: 是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

SQL ServerSQL Server Native Client 標頭檔與程式庫檔案會與 SQL ServerSQL Server 一起安裝。The SQL ServerSQL Server Native Client header and library files are installed with SQL ServerSQL Server. 開發應用程式時,將開發所需的所有檔案複製並安裝到您的開發環境相當重要。When developing an application, it is important to copy and install all of the required files for development to your development environment. 如需有關安裝和轉散發 SQL ServerSQL Server Native Client 的詳細資訊,請參閱安裝 SQL Server Native ClientFor more information about installing and redistributing SQL ServerSQL Server Native Client, see Installing SQL Server Native Client.

SQL ServerSQL Server Native Client 標頭檔和程式庫檔案會安裝到下列位置:The SQL ServerSQL Server Native Client header and library files are installed in the following location:

% PROGRAM FILES% \Microsoft SQL Server\110\SDK%PROGRAM FILES% \Microsoft SQL Server\110\SDK

SQL ServerSQL Server Native Client 標頭檔 (sqlncli.h) 可用於將 SQL ServerSQL Server Native Client 資料存取功能加入到您的自訂應用程式中。The SQL ServerSQL Server Native Client header file (sqlncli.h) can be used to add SQL ServerSQL Server Native Client data access functionality to your custom applications. SQL ServerSQL Server Native Client 標頭檔包含使用 SQL Server 2005 (9.x)SQL Server 2005 (9.x) 中所導入之新功能所需的所有定義、屬性 (Attribute)、屬性 (Property) 與介面。The SQL ServerSQL Server Native Client header file contains all of the definitions, attributes, properties, and interfaces needed to take advantage of the new features introduced in SQL Server 2005 (9.x)SQL Server 2005 (9.x).

除了 SQL ServerSQL Server Native Client 標頭檔之外,還包含一個 sqlncli11.lib 程式庫檔,這是適用於 ODBC 之 SQL ServerSQL Server 大量複製程式 (BCP) 功能的匯出程式庫。In addition to the SQL ServerSQL Server Native Client header file, there is also a sqlncli11.lib library file which is the export library for SQL ServerSQL Server Bulk Copy Program (BCP) functionality for ODBC.

SQL ServerSQL Server Native Client 標頭檔與搭配 Microsoft Data Access Components (MDAC) 所使用的 sqloledb.h 和 odbcss.h 標頭檔具回溯相容性,但是不包含適用於 SQLOLEDB 的 CLSID (適用於 MDAC 隨附之 SQL ServerSQL Server 的 OLE DB 提供者) 或適用於 XML 功能的符號 (不受 SQL ServerSQL Server Native Client 所支援)。The SQL ServerSQL Server Native Client header file is backwards compatible with both the sqloledb.h and odbcss.h header files used with Microsoft Data Access Components (MDAC), but does not contain CLSIDs for SQLOLEDB (the OLE DB provider for SQL ServerSQL Server included with MDAC) or symbols for XML functionality (which is not supported by SQL ServerSQL Server Native Client).

ODBC 應用程式在相同的程式中,無法參考 SQL ServerSQL Server Native Client 標頭 (sqlncli.h) 和 odbcss.h。ODBC applications cannot reference the SQL ServerSQL Server Native Client header (sqlncli.h) and odbcss.h in the same program. 即使您不使用 SQL Server 2005 (9.x)SQL Server 2005 (9.x) 中所導入的任何功能,SQL ServerSQL Server Native Client 標頭檔也會就地使用舊版的 odbcss.h。Even if you are not using any of the features introduced in SQL Server 2005 (9.x)SQL Server 2005 (9.x), the SQL ServerSQL Server Native Client header file will work in place of the older odbcss.h.

使用 SQL ServerSQL Server Native Client OLE DB 提供者的 OLE DB 應用程式僅需要參考 sqlncli.h。OLE DB applications which use the SQL ServerSQL Server Native Client OLE DB provider only need to reference sqlncli.h. 如果應用程式同時使用 MDAC (SQLOLEDB) 和 SQL ServerSQL Server Native Client OLE DB 提供者,則可以同時參考 sqloledb.h 和 sqlncli.h,但是必須先參考 sqloledb.h。If an application uses both MDAC (SQLOLEDB) and the SQL ServerSQL Server Native Client OLE DB provider, it can reference both sqloledb.h and sqlncli.h, but the reference to sqloledb.h must come first.

使用 SQL Server Native Client 標頭檔Using the SQL Server Native Client Header File

若要使用 SQL ServerSQL Server Native Client 標頭檔,您必須在 C /C++程式設計程式碼中使用 include 語句。To use the SQL ServerSQL Server Native Client header file, you must use an include statement within your C/C++ programming code. 下列章節描述如何同時針對 OLE DB 和 ODBC 應用程式執行此動作。The following sections describe how to do this for both OLE DB and ODBC applications.

注意

SQL ServerSQL Server Native Client 標頭檔和程式庫檔案僅能使用 Visual Studio C++ 2002 或更新版本編譯。The SQL ServerSQL Server Native Client header and library files can only be compiled using Visual Studio C++ 2002 or later.

OLE DBOLE DB

透過下列幾行程式碼,在 OLE DB 應用程式中使用 SQL ServerSQL Server Native Client 標頭檔:To use the SQL ServerSQL Server Native Client header file in an OLE DB application, using the following lines of programming code:

#define _SQLNCLI_OLEDB_  
include "sqlncli.h";  

注意

如果應用程式同時使用 OLE DB 和 ODBC API,以上顯示的第一行程式碼應該省略。The first line of code shown above should be omitted if both the OLE DB and ODBC APIs are used by the application. 此外,如果應用程式具有 sqloledb 的include語句,sqlncli 的include語句就必須在它之後。In addition, if the application has an include statement for sqloledb.h, the include statement for sqlncli.h must come after it.

透過 SQL ServerSQL Server Native Client 建立資料來源的連接時,請使用 "SQLNCLI11" 當做提供者名稱字串。When creating a connection to a data source through SQL ServerSQL Server Native Client, use "SQLNCLI11" as the provider name string.

ODBCODBC

透過下列幾行程式碼,在 ODBC 應用程式中使用 SQL ServerSQL Server Native Client 標頭檔:To use the SQL ServerSQL Server Native Client header file in an ODBC application, using the following lines of programming code:

#define _SQLNCLI_ODBC_  
include "sqlncli.h";  

注意

如果應用程式同時使用 OLE DB 和 ODBC API,以上顯示的第一行程式碼應該省略。The first line of code shown above should be omitted if both OLE DB and ODBC APIs are used by the application. 此外,如果應用程式有適用於 odbcss.h 的 #include 陳述式,則必須移除該陳述式。In addition, if the application has an #include statement for odbcss.h, it should be removed.

透過 SQL ServerSQL Server Native Client 建立資料來源的連接時,請使用 "SQL Server Native Client 11.0" 當做驅動程式名稱字串。When creating a connection to a data source through SQL ServerSQL Server Native Client, use "SQL Server Native Client 11.0" as the driver name string.

依版本排列的元件名稱和屬性Component Names and Properties by Version

屬性Property SQL Server Native ClientSQL Server Native Client

SQL Server 2005SQL Server 2005
SQL Server Native Client 10。0SQL Server Native Client 10.0

SQL Server 2008SQL Server 2008
SQL Server Native Client 11.0SQL Server Native Client 11.0

SQL ServerSQL Server
MDACMDAC
ODBC 驅動程式名稱ODBC driver name SQL Native ClientSQL Native Client SQL Server Native Client 10。0SQL Server Native Client 10.0 SQL Server Native Client 11.0SQL Server Native Client 11.0 SQL ServerSQL Server
ODBC 標頭檔名稱ODBC header file name Sqlncli.hSqlncli.h Sqlncli.hSqlncli.h Sqlncli.hSqlncli.h Odbcss.hOdbcss.h
ODBC 驅動程式 DLLODBC driver DLL Sqlncli.dllSqlncli.dll Sqlncl10.dllSqlncl10.dll Sqlncl11.dllSqlncl11.dll sqlsrv32.dllsqlsrv32.dll
適用於 BCP API 的 ODBC 程式庫檔ODBC lib file for BCP APIs Sqlncli.libSqlncli.lib Sqlncli10.libSqlncli10.lib Sqlncli11.libSqlncli11.lib Odbcbcp.libOdbcbcp.lib
適用於 BCP API 的 ODBC DLLODBC DLL for BCP APIs Sqlncli.dllSqlncli.dll Sqlncli10.dllSqlncli10.dll Sqlncli11.dllSqlncli11.dll Odbcbcp.dllOdbcbcp.dll
OLE DB PROGIDOLE DB PROGID SQLNCLISQLNCLI SQLNCLI10SQLNCLI10 SQLNCLI11SQLNCLI11 SQLOLEDBSQLOLEDB
OLE DB 標頭檔名稱OLE DB header file name Sqlncli.hSqlncli.h Sqlncli.hSqlncli.h Sqlncli.hSqlncli.h Sqloledb.hSqloledb.h
OLE DB 提供者 DLLOLE DB provider DLL Sqlncli.dllSqlncli.dll Sqlncli10.dllSqlncli10.dll Sqlncli11.dllSqlncli11.dll Sqloledb.dllSqloledb.dll

sqlncli.h 可透過 SQLNCLI_VER 巨集來支援多個版本的 SQL ServerSQL Server Native Client。sqlncli.h supports multiple version of SQL ServerSQL Server Native Client through the SQLNCLI_VER macro. 根據預設,SQLNCLI_VER 預設為最新版本的 SQL ServerSQL Server Native Client。By default, SQLNCLI_VER defaults to the latest version of SQL ServerSQL Server Native Client. 若要建立使用 sqlncli10.dll 而非 sqlncli11.dll 的應用程式,請將 SQLNCLI_VER 設定為 10。To build an application that uses sqlncli10.dll rather than sqlncli11.dll, set SQLNCLI_VER to 10.

靜態連結與 BCP 函數Static Linking and BCP Functions

當應用程式使用 BCP 函數時,應用程式最好在連接字串中指定用來編譯應用程式之標頭檔與程式庫隨附相同版本的驅動程式。When an application uses BCP functions, it is important for the application to specify in the connection string the driver from the same version that shipped with the header file and library used to compile the application.

例如,如果您使用 SQL ServerSQL Server Native Client 以及 \Program Files\Microsoft SQL Server\110\SDK 中的相關程式庫檔案 (sqlncli11.lib) 和標頭檔 (sqlncli.h) 編譯應用程式,請務必在連接字串中指定 (使用 ODBC 當做範例) "DRIVER={SQL Server Native Client 11.0}"。For example, if you compile an application using SQL ServerSQL Server Native Client, and the associated library file (sqlncli11.lib) and header file (sqlncli.h) from \Program Files\Microsoft SQL Server\110\SDK, make sure to specify (using ODBC as an example) "DRIVER={SQL Server Native Client 11.0}" in the connection string.

如需詳細資訊,請參閱執行大量複製作業For more information, see Performing Performing Bulk Copy Operations.

另請參閱See Also

使用 SQL Server Native Client 建立應用程式Building Applications with SQL Server Native Client