Skip to content

Latest commit

 

History

History
61 lines (40 loc) · 3.54 KB

executing-queries-odbc.md

File metadata and controls

61 lines (40 loc) · 3.54 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic helpviewer_keywords
Executing Queries (ODBC)
An ODBC application can run statements on a SQL Server instance by initializing a connection handle and connecting to a data source.
markingmyname
maghan
03/14/2017
sql
native-client
reference
ODBC applications, executing queries
SQL Server Native Client ODBC driver, statements
ODBC applications, statements
SQL Server Native Client ODBC driver, queries
queries [ODBC]

Executing Queries (ODBC)

[!INCLUDESQL Server Azure SQL Database Synapse Analytics PDW]

After an ODBC application initializes a connection handle and connects with a data source, it allocates one or more statement handles on the connection handle. The application can then execute [!INCLUDEmsCoName] [!INCLUDEssNoVersion] statements on the statement handle. The general sequence of events in executing a SQL statement is:

  1. Set any required statement attributes.

  2. Construct the statement.

  3. Execute the statement.

  4. Retrieve any result sets.

After an application retrieves all the rows in all of the result sets returned by the SQL statement, it can execute another query on the same statement handle. If an application determines that it is not required to retrieve all the rows in a particular result set, it can cancel the rest of the result set by calling either SQLMoreResults or SQLCloseCursor.

If, in an ODBC application, you must execute the same SQL statement multiple times with different data, use a parameter marker denoted by a question mark (?) in the construction of a SQL statement:

INSERT INTO MyTable VALUES (?, ?, ?)  

Each parameter marker can then be bound to a program variable by calling SQLBindParameter.

After all SQL statements execute and their result sets process, the application frees the statement handle.

The [!INCLUDEssNoVersion] Native Client ODBC driver supports multiple statement handles per connection handle. Transactions are managed at the connection level, so that all work performed on all statement handles on a single connection handle are managed as part of the same transaction.

In This Section

See Also

SQL Server Native Client (ODBC)