Using the SQL Native Client Header and Library Files
The SQL Native Client header and library files are installed with SQL Server 2005. When developing an application, it is important to copy and install all of the required files for development to your development environment.
The SQL Native Client header and library files are installed in the following location:
%PROGRAM FILES%\Microsoft SQL Server\90\SDK
The SQL Native Client header file (sqlncli.h) can be used to add SQL Native Client data access functionality to your custom applications. The SQL Native Client header file contains all of the definitions, attributes, properties, and interfaces needed to take advantage of the new features implemented in SQL Server 2005.
In addition to the SQL Native Client header file, there is also a sqlncli.lib library file which is the export library for SQL Server 2005 Bulk Copy Program (BCP) functionality for ODBC.
The SQL 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 Server included with MDAC) or symbols for XML functionality (which is not supported by SQL Native Client).
ODBC applications cannot reference the SQL Native Client header (sqlncli.h) and odbcss.h in the same program. Even if you are not using any of the new features that SQL Server 2005 provides, the SQL Native Client header file will work in place of the older odbcss.h.
OLE DB applications which use the SQL Native Client OLE DB provider only need to reference sqlncli.h. If an application uses both MDAC (SQLOLEDB) and the SQL Native Client OLE DB provider, it can reference both sqloledb.h and sqlncli.h, but the reference to sqloledb.h must come first.
By default the SQL Native Client installer only installs the client components when installed independent of SQL Server 2005. To install all components (client and the SDK components), specify ADDLOCAL=All on the command line. For example:
msiexec /i sqlncli.msi ADDLOCAL=ALL APPGUID={0CC618CE-F36A-415E-84B4-FB1BFF6967E1}
Using the SQL Native Client Header File
In order to use the SQL Native Client header file, you must use an include statement within your C/C++ programming code. The following sections describe how to do this for both OLE DB and ODBC applications.
附註: |
---|
The SQL Native Client header and library files can only be compiled using Visual Studio C++ 2002 or later. |
OLE DB
To use the SQL Native Client header file in an OLE DB application, using the following lines of programming code:
#define _SQLNCLI_OLEDB_
include "sqlncli.h";
附註: |
---|
The first line of code shown above should be omitted if both the OLE DB and ODBC APIs are used by the application. In addition, if the application has an include statement for sqloledb.h, the include statement for sqlncli.h must come after it. If you #define _SQLNCLI_OLEDB_ , ensure that you installed service pack 2 (SP2) of SQL Server 2005. |
When creating a connection to a data source through SQL Native Client, use "SQLNCLI" as the provider name string.
ODBC
To use the SQL Native Client header file in an ODBC application, using the following lines of programming code:
#define _SQLNCLI_ODBC_
include "sqlncli.h";
附註: |
---|
The first line of code shown above should be omitted if both OLE DB and ODBC APIs are used by the application. In addition, if the application has a #include statement for odbcss.h, it should be removed. If you #define _SQLNCLI_ODBC_ , ensure that you installed service pack 2 (SP2) of SQL Server 2005. |
When creating a connection to a data source through SQL Native Client, use "SQL Native Client" as the driver name string.
請參閱
其他資源
Building Applications with SQL Native Client