docs/en/14-reference/05-connector/50-odbc.md
TDengine ODBC is an ODBC driver implemented for TDengine, supporting applications on Windows systems (such as PowerBI and others) as well as user-customized applications to access TDengine databases locally, remotely, and via cloud services through the ODBC standard interface.
TDengine ODBC offers two types of connections to the TDengine database: WebSocket (recommended) and native connections. Different connection methods can be set for the TDengine data source when in use. WebSocket connection must be used when accessing cloud services.
TDengine ODBC provides both 64-bit and 32-bit drivers. However, the 32-bit version is only supported by the TSDB-Enterprise and only supports WebSocket connections.
:::note
:::
Supports all ODBC versions.
Only supports the Windows platform. Windows requires the installation of the VC runtime library, which can be downloaded here VC Runtime Library. If you have already installed the VS development tools, you can ignore this.
Install the TDengine Windows client. Version 3.2.1.0 or above includes the TDengine ODBC 64-bit driver; version 3.3.3.0 or above includes the TDengine ODBC 32/64-bit driver.
TDengine ODBC supports two ways to connect to the TDengine database: WebSocket connection and Native connection, with the following differences:
Only WebSocket connection mode is supported when accessing cloud services.
Only WebSocket connection mode is supported for 32-bit applications.
WebSocket connection has better compatibility, generally does not require upgrading the client library with TDengine database server upgrades.
Native connection usually performs slightly better, but must be consistent with the version of the TDengine database server.
For general users, it is recommended to use the WebSocket connection mode, as the performance difference with Native is not significant, and compatibility is better.
Search and open the ODBC Data Sources (32-bit) or ODBC Data Sources (64-bit) management tool from the Start menu
Select the User DSN tab, and proceed to the "Create Data Source" interface via the Add(D) button
Choose the data source you want to add, here we select TDengine
Click finish, enter the TDengine ODBC data source configuration page, fill in the following necessary information
4.1 DSN: Data Source Name, required, name the newly added ODBC data source
4.2 Connection Type: Required, select the connection type, here choose WebSocket
4.3 URL: Required, ODBC data source URL, example: http://localhost:6041, cloud service URL example: https://gw.cloud.tdengine.com?token=your_token
4.4 Database: Optional, the default database to connect to
4.5 Username: Optional, for use in step 5 connection testing only, database username, if not specified, TDengine defaults to root
4.6 Password: Optional, for use in step 5 connection testing only, database user password, if not specified, TDengine defaults to taosdata
4.7 Compatible Software: Supports compatibility adaptation for industrial software such as KingSCADA, Kepware, etc., with ADO support included. Usually, the default value General is sufficient for most scenarios
Click Test Connection to test the connection status. If successful, a "Successfully connected to URL" message will appear.
Click OK to save the configuration and exit.
You can also select a pre-configured data source name in step 2 and enter the configuration page through the Configure button to modify existing configurations.
Search and open ODBC Data Sources (64-bit) management tool from the Start menu (make sure not to select ODBC Data Sources (32-bit)).
Select the User DSN tab, and enter the "Create Data Source" interface through the Add(D) button.
Choose the data source you want to add, here we select TDengine.
Click finish to enter the TDengine ODBC data source configuration page, fill in the necessary information as follows:
4.1 DSN: Data Source Name is required, name the newly added ODBC data source.
4.2 Connection Type: Mandatory, select the type of connection, here choose Native.
4.3 Server: Required, ODBC data source server address, example: localhost:6030.
4.4 Database: Optional, the default database to connect to.
4.5 Username: Optional, used only for testing the connection in step 5, database username, if not specified, TDengine defaults to root.
4.6 Password: Optional, used only for testing the connection in step 5, database user password, if not specified, TDengine defaults to taosdata.
4.7 Compatible Software: Supports compatibility adaptation for industrial software such as KingSCADA, Kepware, etc., with ADO support included. Usually, the default value General is sufficient for most scenarios.
Click Test Connection to test the connection status. If successful, a "Connection successful" message will appear.
Click OK to save the configuration and exit.
You can also select a pre-configured data source name in step 2 and enter the configuration page through the Configure button to modify existing configurations.
The platforms supported by the native connection method are consistent with those supported by the TDengine Windows X64 client driver. In addition to this, the WebSocket connection method also supports 32-bit applications running on Windows X64 systems.
| taos_odbc Version | Major Changes | TDengine Version |
|---|---|---|
| v1.1.1 | Support ADO access to TDengine ODBC 32/64 interface. | 3.3.3.0 and higher |
| v1.1.0 | 1. Supports view functionality. |
The table below explains how the ODBC connector maps server data types to default SQL and C data types.
| TDengine Type | SQL Type | C Type |
|---|---|---|
| TIMESTAMP | SQL_TYPE_TIMESTAMP | SQL_C_TIMESTAMP |
| INT | SQL_INTEGER | SQL_C_SLONG |
| INT UNSIGNED | SQL_INTEGER | SQL_C_ULONG |
| BIGINT | SQL_BIGINT | SQL_C_SBIGINT |
| BIGINT UNSIGNED | SQL_BIGINT | SQL_C_UBIGINT |
| FLOAT | SQL_REAL | SQL_C_FLOAT |
| DOUBLE | SQL_DOUBLE | SQL_C_DOUBLE |
| BINARY | SQL_BINARY | SQL_C_BINARY |
| SMALLINT | SQL_SMALLINT | SQL_C_SSHORT |
| SMALLINT UNSIGNED | SQL_SMALLINT | SQL_C_USHORT |
| TINYINT | SQL_TINYINT | SQL_C_STINYINT |
| TINYINT UNSIGNED | SQL_TINYINT | SQL_C_UTINYINT |
| BOOL | SQL_BIT | SQL_C_BIT |
| NCHAR | SQL_VARCHAR | SQL_C_CHAR |
| VARCHAR | SQL_VARCHAR | SQL_C_CHAR |
| JSON | SQL_WVARCHAR | SQL_C_WCHAR |
| GEOMETRY | SQL_VARBINARY | SQL_C_BINARY |
| VARBINARY | SQL_VARBINARY | SQL_C_BINARY |
| ODBC/Setup API | Linux | macOS | Windows | Note |
|---|---|---|---|---|
| ConfigDSN | ❌ | ❌ | ✅ | |
| ConfigDriver | ❌ | ❌ | ✅ | |
| ConfigTranslator | ❌ | ❌ | ❌ | |
| SQLAllocHandle | ✅ | ✅ | ✅ | |
| SQLBindCol | ✅ | ✅ | ✅ | Column-Wise Binding only |
| SQLBindParameter | ✅ | ✅ | ✅ | Column-Wise Binding only |
| SQLBrowseConnect | ❌ | ❌ | ❌ | |
| SQLBulkOperations | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLCloseCursor | ✅ | ✅ | ✅ | |
| SQLColAttribute | ✅ | ✅ | ✅ | |
| SQLColumnPrivileges | ❌ | ❌ | ❌ | TDengine has no strict counterpart |
| SQLColumns | ✅ | ✅ | ✅ | |
| SQLCompleteAsync | ❌ | ❌ | ❌ | |
| SQLConnect | ✅ | ✅ | ✅ | |
| SQLCopyDesc | ❌ | ❌ | ❌ | |
| SQLDescribeCol | ✅ | ✅ | ✅ | |
| SQLDescribeParam | ✅ | ✅ | ✅ | |
| SQLDisconnect | ✅ | ✅ | ✅ | |
| SQLDriverConnect | ✅ | ✅ | ✅ | |
| SQLEndTran | ✅ | ✅ | ✅ | TDengine is non-transactional, thus this is at most simulating |
| SQLExecDirect | ✅ | ✅ | ✅ | |
| SQLExecute | ✅ | ✅ | ✅ | |
| SQLExtendedFetch | ❌ | ❌ | ❌ | |
| SQLFetch | ✅ | ✅ | ✅ | |
| SQLFetchScroll | ✅ | ✅ | ✅ | TDengine has no counterpart, just implement SQL_FETCH_NEXT |
| SQLForeignKeys | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLFreeHandle | ✅ | ✅ | ✅ | |
| SQLFreeStmt | ✅ | ✅ | ✅ | |
| SQLGetConnectAttr | ✅ | ✅ | ✅ | Supports partial attributes; unsupported attributes are listed below. |
| SQLGetCursorName | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLGetData | ✅ | ✅ | ✅ | |
| SQLGetDescField | ❌ | ❌ | ❌ | |
| SQLGetDescRec | ❌ | ❌ | ❌ | |
| SQLGetDiagField | ✅ | ✅ | ✅ | |
| SQLGetDiagRec | ✅ | ✅ | ✅ | |
| SQLGetEnvAttr | ✅ | ✅ | ✅ | |
| SQLGetInfo | ✅ | ✅ | ✅ | |
| SQLGetStmtAttr | ✅ | ✅ | ✅ | Supports partial attributes; unsupported attributes are listed below. |
| SQLGetTypeInfo | ✅ | ✅ | ✅ | |
| SQLMoreResults | ✅ | ✅ | ✅ | |
| SQLNativeSql | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLNumParams | ✅ | ✅ | ✅ | |
| SQLNumResultCols | ✅ | ✅ | ✅ | |
| SQLParamData | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLPrepare | ✅ | ✅ | ✅ | |
| SQLPrimaryKeys | ✅ | ✅ | ✅ | |
| SQLProcedureColumns | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLProcedures | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLPutData | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLRowCount | ✅ | ✅ | ✅ | |
| SQLSetConnectAttr | ✅ | ✅ | ✅ | Supports partial attributes; unsupported attributes are listed below. |
| SQLSetCursorName | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLSetDescField | ❌ | ❌ | ❌ | |
| SQLSetDescRec | ❌ | ❌ | ❌ | |
| SQLSetEnvAttr | ✅ | ✅ | ✅ | |
| SQLSetPos | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLSetStmtAttr | ✅ | ✅ | ✅ | Supports partial attributes; unsupported attributes are listed below. |
| SQLSpecialColumns | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLStatistics | ❌ | ❌ | ❌ | TDengine has no counterpart |
| SQLTablePrivileges | ❌ | ❌ | ❌ | TDengine has no strict counterpart |
| SQLTables | ✅ | ✅ | ✅ |
| Attribute | Note |
|---|---|
| SQL_ATTR_CONCURRENCY | TDengine has no updatable-CURSOR mechanism |
| SQL_ATTR_FETCH_BOOKMARK_PTR | TDengine has no BOOKMARK mechanism |
| SQL_ATTR_IMP_PARAM_DESC | |
| SQL_ATTR_IMP_ROW_DESC | |
| SQL_ATTR_KEYSET_SIZE | |
| SQL_ATTR_PARAM_BIND_OFFSET_PTR | |
| SQL_ATTR_PARAM_OPERATION_PTR | |
| SQL_ATTR_ROW_NUMBER | Readonly attribute |
| SQL_ATTR_ROW_OPERATION_PTR | |
| SQL_ATTR_SIMULATE_CURSOR |
| Attribute | Note |
|---|---|
| SQL_ATTR_AUTO_IPD | Readonly attribute |
| SQL_ATTR_CONNECTION_DEAD | Readonly attribute |
| SQL_ATTR_ENLIST_IN_DTC | |
| SQL_ATTR_PACKET_SIZE | |
| SQL_ATTR_TRACE | |
| SQL_ATTR_TRACEFILE | |
| SQL_ATTR_TRANSLATE_LIB | |
| SQL_ATTR_TRANSLATE_OPTION |
| programming language | ODBC-API or bindings/plugins |
|---|---|
| C/C++ | ODBC-API |
| CSharp | System.Data.Odbc |
| Erlang | odbc module |
| Go | odbc, database/sql |
| Haskell | HDBC, HDBC-odbc |
| Common Lisp | plain-odbc |
| Nodejs | odbc |
| Python3 | pyodbc |
| Rust | odbc |
This section summarizes the ODBC API by functionality. For a complete ODBC API reference, please visit the Microsoft Open Database Connectivity (ODBC).
API: ConfigDSN
API: ConfigDriver
API: ConfigTranslator
API: SQLAllocHandle
API: SQLConnect
API: SQLDriverConnect
API: SQLBrowseConnect
API: SQLAllocEnv
API: SQLAllocConnect
API: SQLDataSources
API: SQLDrivers
API: SQLGetInfo
API: SQLGetFunctions
API: SQLGetTypeInfo
API: SQLSetConnectAttr
API: SQLGetConnectAttr
API: SQLSetConnectOption
API: SQLGetConnectOption
API: SQLSetEnvAttr
API: SQLGetEnvAttr
API: SQLSetStmtAttr
API: SQLGetStmtAttr
API: SQLSetStmtOption
API: SQLGetStmtOption
API: SQLAllocStmt
API: SQLPrepare
API: SQLBindCol
API: SQLBindParameter
API: SQLGetCursorName
API: SQLSetCursorName
API: SQLSetScrollOptions
API: SQLExecute
API: SQLExecDirect
API: SQLNativeSql
API: SQLDescribeParam
API: SQLNumParams
API: SQLParamData
API: SQLPutData
API: SQLRowCount
API: SQLNumResultCols
API: SQLDescribeCol
API: SQLColAttribute
API: SQLColAttributes
API: SQLGetData
API: SQLMoreResults
API: SQLFetch
API: SQLFetchScroll
API: SQLExtendedFetch
API: SQLSetPos
API: SQLBulkOperations
API: SQLError
API: SQLGetDiagField
API: SQLGetDiagRec
API: SQLColumnPrivileges
API: SQLColumns
API: SQLForeignKeys
API: SQLPrimaryKeys
API: SQLSpecialColumns
API: SQLStatistics
API: SQLTablePrivileges
API: SQLTables
API: SQLProcedures
API: SQLProcedureColumns
API: SQLTransact
API: SQLEndTran
API: SQLDisconnect
API: SQLFreeHandle
API: SQLFreeConnect
API: SQLFreeEnv
API: SQLFreeStmt
API: SQLCloseCursor