Bewerken

Delen via


Creating a Driver Application

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Analytics Platform System (PDW)

Important

SQL Server Native Client (SNAC) isn't shipped with:

  • SQL Server 2022 (16.x) and later versions
  • SQL Server Management Studio 19 and later versions

The SQL Server Native Client (SQLNCLI or SQLNCLI11) and the legacy Microsoft OLE DB Provider for SQL Server (SQLOLEDB) aren't recommended for new application development.

For new projects, use one of the following drivers:

For SQLNCLI that ships as a component of SQL Server Database Engine (versions 2012 through 2019), see this Support Lifecycle exception.

ODBC architecture has four components that perform the following functions.

Component Function
Application Calls ODBC functions to communicate with an ODBC data source, submits SQL statements, and processes result sets.
Driver Manager Manages communication between an application and all ODBC drivers used by the application.
Driver Processes all ODBC function calls from the application, connects to a data source, passes SQL statements from the application to the data source, and returns results to the application. If necessary, the driver translates ODBC SQL from the application to native SQL used by the data source.
Data source Contains all information a driver needs to access a specific instance of data in a DBMS.

An application that uses the SQL Server Native Client ODBC driver to communicate with an instance of SQL Server performs the following tasks:

  • Connects with a data source

  • Sends SQL statements to the data source

  • Processes the results of statements from the data source

  • Processes errors and messages

  • Terminates the connection to the data source

A more complex application written for the SQL Server Native Client ODBC driver might also perform the following tasks:

  • Use cursors to control location in a result set

  • Request commit or rollback operations for transaction control

  • Perform distributed transactions involving two or more servers

  • Run stored procedures on the remote server

  • Call catalog functions to inquire about the attributes of a result set

  • Perform bulk copy operations

  • Manage large data (varchar(max), nvarchar(max), and varbinary(max) columns) operations

  • Use reconnection logic to facilitate failover when database mirroring is configured

  • Log performance data and long-running queries

To make ODBC function calls, a C or C++ application must include the sql.h, sqlext.h, and sqltypes.h header files. To make calls to the ODBC installer API functions, an application must include the odbcinst.h header file. A Unicode ODBC application must include the sqlucode.h header file. ODBC applications must be linked with the odbc32.lib file. ODBC applications that call the ODBC installer API functions must be linked with the odbccp32.lib file. These files are included in the Windows Platform SDK.

Many ODBC drivers, including the SQL Server Native Client ODBC driver, offer driver-specific ODBC extensions. To take advantage of SQL Server Native Client ODBC driver-specific extensions, an application should include the sqlncli.h header file. This header file contains:

  • SQL Server Native Client ODBC driver-specific connection attributes.

  • SQL Server Native Client ODBC driver-specific statement attributes.

  • SQL Server Native Client ODBC driver-specific column attributes.

  • SQL Server-specific data types.

  • SQL Server-specific user-defined data types.

  • SQL Server Native Client ODBC driver-specific SQLGetInfo types.

  • SQL Server Native Client ODBC driver diagnostics fields.

  • SQL Server-specific diagnostic dynamic function codes.

  • C/C++ type definitions for SQL Server-specific native C data types (returned when columns bound to C data type SQL_C_BINARY).

  • Type definition for the SQLPERF data structure.

  • Bulk copy macros and prototypes to support bulk copy API usage through an ODBC connection.

  • Call the distributed query metadata API functions for lists of linked servers and their catalogs.

Any C or C++ ODBC application that uses the bulk copy feature of the SQL Server Native Client ODBC driver must be linked with the sqlncli11.lib file. Applications calling the distributed query metadata API functions must also be linked with sqlncli11.lib. The sqlncli.h and sqlncli11.lib files are distributed as part of the SQL Server developer's tools. The SQL Server Include and Lib directories should be in the compiler's INCLUDE and LIB paths as in the following:

LIB=c:\Program Files\Microsoft Data Access SDK 2.8\Libs\x86\lib;C:\Program Files\Microsoft SQL Server\100\Tools\SDK\Lib;  
INCLUDE=c:\Program Files\Microsoft Data Access SDK 2.8\inc;C:\Program Files\Microsoft SQL Server\100\Tools\SDK\Include;  

One design decision made early in the process of building an application is whether the application needs to have multiple ODBC calls outstanding at the same time. There are two methods for supporting multiple concurrent ODBC calls, which are described in the remaining topics in this section. For more information, see the ODBC Programmer's Reference.

In This Section

See Also

SQL Server Native Client (ODBC)