一直不明白ODBC是个什么东东,虽然一次次碰到,却从没用过,看Wikipedia上的描述,可以访问各种数据库、Excel、CSV等,可以剥离数据库和操作系统依赖,简直神乎其神。不过这样的描述太抽象概括了,和过去一样,我只能望文生义。于是决定尝试使用Window 10自带的 ODBC 数据源 (ODBC Data Sources) 管理工具对ODBC有些具体的认识。
Open Database Connectivity (ODBC) is a standard application programming interface (API) for accessing database management systems (DBMS) . The designers of ODBC aimed to make it independent of database systems and operating systems. An application written using ODBC can be ported to other platforms, both on the client and server side, with few changes to the data access code.
ODBC accomplishes DBMS independence by using an ODBC driver as a translation layer between the application and the DBMS. The application uses ODBC functions through an ODBC driver manager with which it is linked, and the driver passes the query to the DBMS. An ODBC driver can be thought of as analogous to a printer driver or other driver, providing a standard set of functions for the application to use, and implementing DBMS-specific functionality. An application that can use ODBC is referred to as "ODBC-compliant". Any ODBC-compliant application can access any DBMS for which a driver is installed. Drivers exist for all major DBMSs, many other data sources like address book systems and Microsoft Excel, and even for text or comma-separated values (CSV) files.
控制面板\管理工具打开ODBC 数据源管理程序 (也可以运行odbcad32.exe),各个TAB点了一遍, 确实很强大的感觉。对ODBC 数据源管理器的介绍参见:https://docs.microsoft.com/zh-cn/sql/odbc/admin/odbc-data-source-administrator,另外,点击右下角的帮助按钮也有早期的详尽文档供参考 (https://docs.microsoft.com/en-us/previous-versions/windows/desktop/odbc/dn170412(v=vs.85)。
1. 用户DNS(Data Source Name)默认提供了Access 和 Excel 的数据源 (应该是安装了office套件的缘故)
2. 系统DNS是的空的,感觉是配置了以后,所有用户都能使用的数据源
3. 文件DSN,看上去似乎可以通过添加ODBC数据源访问本机文件
4. 驱动程序和连接池 (安装了SQL Server,所以有3个驱动程序)
5. 跟踪提供了日志记录功能,方便调试
6. 关于,描述了ODBC的核心组件
废话少说,让我们手动建立一个ODBC 连接到 SQL Server 数据库DNS来一探究竟 (注: 也可以使用命令行工具odbcconf.exe, 语法Helper对话框odbcconf -H, 详细使用参见: https://docs.microsoft.com/zh-cn/sql/odbc/odbcconf-exe)
未完待续。。。
SQLDriverConnect 函数: https://docs.microsoft.com/zh-cn/sql/odbc/reference/syntax/sqldriverconnect-function
官方不是很易懂易上手的数据源向导设置参考: https://docs.microsoft.com/zh-cn/sql/connect/odbc/windows/dsn-wizard-1