Using the SQL Server Native Client Header and Library Files

 

System_CAPS_ICON_warning.jpg Warning

SQL Server Native Client (SNAC) is not supported beyond SQL Server 2012. Avoid using SNAC in new development work, and plan to modify applications that currently use it. The Microsoft ODBC Driver for SQL Server provides native connectivity from Windows to Microsoft SQL Server and Microsoft Azure SQL Database.

The SQL Server Native Client header and library files are installed with SQL Server. When developing an application, it is important to copy and install all of the required files for development to your development environment. For more information about installing and redistributing SQL Server Native Client, see Installing SQL Server Native Client.

The SQL Server Native Client header and library files are installed in the following location:

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

The SQL Server Native Client header file (sqlncli.h) can be used to add SQL Server Native Client data access functionality to your custom applications. The SQL 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.

In addition to the SQL Server Native Client header file, there is also a sqlncli11.lib library file which is the export library for SQL Server Bulk Copy Program (BCP) functionality for ODBC.

The SQL 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 Server included with MDAC) or symbols for XML functionality (which is not supported by SQL Server Native Client).

ODBC applications cannot reference the SQL Server Native Client header (sqlncli.h) and odbcss.h in the same program. Even if you are not using any of the features introduced in SQL Server 2005, the SQL Server Native Client header file will work in place of the older odbcss.h.

OLE DB applications which use the SQL Server Native Client OLE DB provider only need to reference sqlncli.h. If an application uses both MDAC (SQLOLEDB) and the SQL Server Native Client OLE DB provider, it can reference both sqloledb.h and sqlncli.h, but the reference to sqloledb.h must come first.

To use the SQL Server 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.

System_CAPS_ICON_note.jpg Note


The SQL Server Native Client header and library files can only be compiled using Visual Studio C++ 2002 or later.

OLE DB

To use the SQL Server Native Client header file in an OLE DB application, using the following lines of programming code:

#define _SQLNCLI_OLEDB_  
include "sqlncli.h";  

System_CAPS_ICON_note.jpg Note


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.

When creating a connection to a data source through SQL Server Native Client, use "SQLNCLI11" as the provider name string.

ODBC

To use the SQL Server Native Client header file in an ODBC application, using the following lines of programming code:

#define _SQLNCLI_ODBC_  
include "sqlncli.h";  

System_CAPS_ICON_note.jpg Note


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 an #include statement for odbcss.h, it should be removed.

When creating a connection to a data source through SQL Server Native Client, use "SQL Server Native Client 11.0" as the driver name string.

PropertySQL Server Native Client

SQL Server 2005
SQL Server Native Client 10.0

SQL Server 2008
SQL Server Native Client 11.0

 SQL Server 2016
MDAC
ODBC driver nameSQL Native ClientSQL Server Native Client 10.0SQL Server Native Client 11.0SQL Server
ODBC header file nameSqlncli.hSqlncli.hSqlncli.hOdbcss.h
ODBC driver DLLSqlncli.dllSqlncl10.dllSqlncl11.dllsqlsrv32.dll
ODBC lib file for BCP APIsSqlncli.libSqlncli10.libSqlncli11.libOdbcbcp.lib
ODBC DLL for BCP APIsSqlncli.dllSqlncli10.dllSqlncli11.dllOdbcbcp.dll
OLE DB PROGIDSQLNCLISQLNCLI10SQLNCLI11SQLOLEDB
OLE DB header file nameSqlncli.hSqlncli.hSqlncli.hSqloledb.h
OLE DB provider DLLSqlncli.dllSqlncli10.dllSqlncli11.dllSqloledb.dll

sqlncli.h supports multiple version of SQL Server Native Client through the SQLNCLI_VER macro. By default, SQLNCLI_VER defaults to the latest version of SQL Server Native Client. To build an application that uses sqlncli10.dll rather than sqlncli11.dll, set SQLNCLI_VER to 10.

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.

For example, if you compile an application using SQL 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.

Building Applications with SQL Server Native Client

Community Additions

ADD
Show: