ODBC Driver Development

By Vikash Agarwal, May 01, 2002

Open your database system to the world. Vikash steps through developing an ODBC driver, using XML-SOAP for encoding the calls and results. The communication between the driver and DBMS takes place over sockets.

The primary design goal of ODBC (Open Database Connectivity) is to allow an application to access different databases, simultaneously, with the same source code.


An ODBC client always calls a fixed set of APIs to access data from any ODBC-compliant DBMS. The APIs for each DBMS together form an ODBC driver for that DBMS. The client does not statically link with any ODBC driver; in Windows, the driver is implemented as a DLL allowing it to be loaded at run time. The name, parameters, and what these APIs/functions are expected to do is defined by the ODBC standard. The use of drivers isolates applications from database-specific calls in the same way that printer drivers isolate word processing programs from printer-specific commands.

The aim of this article is to help you create an ODBC driver for your DBMS. I will discuss the ODBC architecture and then create a simple ODBC client. This will give you an idea of what is expected from your driver. Then we will proceed to create the driver itself.

I developed my ODBC driver on Windows 2000 professional using Visual C++ 6.0, so all the extra tools and samples mentioned are from Microsoft unless otherwise noted. Microsoft groups ODBC together with its other data access technologies under MDAC (Microsoft Data Access Components). MDAC is available as part of Platform SDK or as a separate download at http://www.microsoft.com/data/whatcom.htm.

ODBC Driver and Architecture

The ODBC architecture has four components:

  • The Application performs processing and calls ODBC functions to submit SQL statements and retrieve results.
  • TheDriver Manager is a DLL provided on a Windows platform as part of the ODBC components. It manages certain tasks common to all ODBC clients. For example, it manages loading and unloading of driver DLLs, and creation and maintenance of pointers to driver functions so you don’t have to use LoadLibrary and GetProcAddress for each driver you want to use. It performs some basic error checking before a call is forwarded to the driver and also implements certain functions like SQLDataSourcesSQLDrivers, and SQLGetFunctionswithin itself.
  • The Driver processes ODBC function calls, submits SQL requests to a specific data source, and returns results to the application. If necessary, the driver modifies an application’s request so that the request conforms to syntax supported by the associated DBMS.
  • The Data source consists of the data the user wants to access and its associated operating system, DBMS, and network platform (if any) used to access the DBMS.

Using a Data Source

A data source is simply the source of the data. It can be a file, a particular database on a DBMS, or even a live data feed. For example, a data source might be an Oracle DBMS running on an OS/2 operating system, accessed by Novell Netware; an IBM DB2 DBMS accessed through a gateway; a collection of Xbase files in a server directory; or a local Microsoft Access database file. The purpose of a data source is to gather all of the technical information needed to access the data — the driver name, network address, network software, and so on — into a single place and hide it from the user. The user should be able to look at a list that includes Payroll, Inventory, and Personnel, choose Payroll from the list, and have the application connect to the payroll data, all without knowing where the payroll data resides or how the application got to it. File data sources are stored in a file and allow connection information to be used repeatedly by a single user or shared among several users. When a file data source is used, the Driver Manager makes the connection to the data source using the information in a .dsn file. This file can be manipulated like any other file. A file data source does not have a data source name, as does a machine data source, and is not registered to any one user (UserDSN) or machine (SystemDSN).

A file data source streamlines the connection process, because the .dsn file contains the connection string that would otherwise have to be built for a call to the SQLDriverConnect function. Another advantage of the .dsn file is that it can be copied to any machine, so identical data sources can be used by many machines as long as they have the appropriate driver installed. A file data source can also be shared by applications. A shareable file data source can be placed on a network and used simultaneously by multiple applications. DSNs created for individual users will be called User DSNs are registered in the following system information key:

1
2
3
4
HKEY_CURRENT_USER
    SOFTWARE
        ODBC
            Odbc.ini

Similarly, system DSNs are tied up to a particular system, and any user of that system can use them. System DSNs are registered in the following system information key:

1
2
3
4
HKEY_LOCAL_MACHINE
    SOFTWARE
        ODBC
            Odbc.ini

Figure 1: The ODBC architecture.

The ODBC API is used in two places: between the application and the Driver Manager, and between the Driver Manager and each driver. The communication between the driver and the data source is the individual vendor’s choice. Note that you can create, implement, and use a driver without the driver manager, so do not worry about the typical “too many layers” situation.

The driver packages the API calls along with the parameters and sends it to the DBMS or data source. The DBMS processes the call and sends the results back to the driver, which throws back the results to the ODBC clients. I am going to use XML-SOAP for encoding the calls and results. The communication between the driver and DBMS takes place over sockets. We will discuss more on this in the section “Packaging calls in XML-SOAP and communicating over sockets”. You will need to have some idea about XML and sockets in addition to general C programming and DLL creation.

To make your database server work with your driver, a thin layer has to be added to it. This layer understands the XML-SOAP encoded calls from the driver; it interprets them to existing functions in your DBMS engine and encodes back the results as XML-SOAP. The core of this layer is an XML parser. The parser is also required as part of your driver. I have provided one in the download, but you are free to use one of your choice with necessary changes to the sample code.

It is important to understand that ODBC is designed to expose database capabilities, not to supplement them. It makes your DBMS accessible to more clients through a commonly accepted standard. One exception to this is a file-based driver, which works with raw data and therefore also implements the functionality. A driver working on a DBF file may or may not implement update and is not bound by any other engine. However, the driver for SQL Server is limited by the functionality provided by the SQL server engine, since the driver itself never touches the raw data files.

I am going to create a driver for a server based DBMS, since the aim is only to expose existing functionality. Besides, I feel that a file-based DBMS has little to offer in today’s client-server world.

ODBC Driver Development的更多相关文章

  1. 安装mysql odbc遇到error 1918.errror installing ODBC driver mysql ODBC 5.3 ANSI Drive

    环境:Windows server2008r2 安装mysql-connector-odbc-5.3.6-win32 报错 相信错误信息:Error 1918.errror installing OD ...

  2. Adaptive Server Enterprise ODBC driver connection strings

    Adaptive Server Enterprise 15.0 Driver={Adaptive Server Enterprise};app=myAppName;server=myServerAdd ...

  3. MongoDB ODBC Driver for Data Integration with Power BI

    This guide will walk you through connecting Microsoft Power BI to a MongoDB DataSet using our MongoD ...

  4. 【原创】Qt 使用ODBC driver 连接SQL Server

    最近在做数据库的课程设计.第一个需要解决的问题是使用什么工具来实现这个系统.经过一番资料查找,决定使用SQL Server Express 2012作为服务器,使用Qt作为编写客户端程序语言.问题是c ...

  5. [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]列名 'user1' 无效

    唉,还是自己对php执行sql语句运用不熟练.... 我的错误代码是这样的,(解决办法在最后) $re=sqlsrv_query($conn, "select * from visitor ...

  6. python 通过Sybase ASE ODBC Driver访问sybase数据库,无需配置DSN【自己整理的】

    Python语言对于开发工程师或者测试工程师来说,应该是最高效的开发语言之一.但python访问sybase数据库的资料相对少见.而且sybase字符集为GB1803时,python访问sybase库 ...

  7. [ERROR]pyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]SQL Server 阻止了对组件“xp_cmdshell”的 过程“sys.xp_cmdshell”的访问

    环境: Windows 2012 R2 SQL Server 2014 通过MSSQL查询数据库服务器时间,报错如下: pyodbc.ProgrammingError: (', '[42000] [M ...

  8. Driver development

    Windows Driver Kit (WDK) https://msdn.microsoft.com/en-us/library/windows/hardware/ff557573(v=vs.85) ...

  9. vcenter安装错误The DSN is pointing to anunspported ODBC driver...

    在安装vcenter server中采用现有独立sql server数据库时出现下列错误. 这是由于当前独立数据库版本和当前系统的客户端驱动不匹配.导致我们在odbc中配置dsn无法正常运行. 如sq ...

随机推荐

  1. Ubuntu 下串口调试工具

    1. cutecom 安装:sudo apt-get install cutecom 打开方式: 在终端输入:cutecom,即可打开串口工具 或者在应用中,点击 cutecom 图标打开 打开后的界 ...

  2. linux服务器安全配置攻略

    引言: 最小的权限+最少的服务=最大的安全 所以,无论是配置任何服务器,我们都必须把不用的服务关闭.把系统权限设置到最小话,这样才能保证服务器最大的安全.下面是CentOS服务器安全设置,供大家参考. ...

  3. 谷歌将用QUIC传输层技术加速互联网

    安全这个话题,要感谢斯诺登,过去的安全就是攻和防之间的关系,即我们用一种什么样的体系.架构和模式去构建一个密不可破的安全系统.” 对IETF工作组忽视外部观察者看起来是一件甚么微不足道的事情的能力感到 ...

  4. css-按钮中有图片和文字,怎么才能让文字和图片都中??

    <div class="btn1 trans" > <img src="../../images/img/add.png"/> < ...

  5. 8:Spring Boot Shiro记住密码

    1,添加Cookie 2,添加安全管理器中 3,配置记住我, 4 ,在登录页面中加我rememberMe复选框 /** * 1.配置Cookie对象 * 记住我的cookie:rememberMe * ...

  6. makefile 赋值

    = 是最基本的赋值:= 是覆盖之前的值?= 是如果没有被赋值过就赋予等号后面的值+= 是添加等号后面的值

  7. luogu P1162 填涂颜色 x

    P1162 填涂颜色 题目描述 由数字0 组成的方阵中,有一任意形状闭合圈,闭合圈由数字1构成,围圈时只走上下左右4个方向.现要求把闭合圈内的所有空间都填写成2.例如:6X6的方阵(n=6),涂色前和 ...

  8. Solr分组查询

     项目中需要实时的返回一下统计的东西,因此就要进行分组,在获取一些东西,代码拿不出来,因此分享一篇,还是很使用的. facet搜索 /** * * 搜索功能优化-关键词搜索 * 搜索范围:商品名称.店 ...

  9. #1126-JSP客户端请求

    JSP 客户端请求 当浏览器请求一个网页时,它会向网络服务器发送一系列不能被直接读取的信息,因为这些信息是作为HTTP信息头的一部分来传送的.您可以查阅HTTP协议来获得更多的信息. 下表列出了浏览器 ...

  10. Redis分布式锁服务

    阅读目录: 概述 分布式锁 多实例分布式锁 总结 概述 在多线程环境下,通常会使用锁来保证有且只有一个线程来操作共享资源.比如: object obj = new object(); lock (ob ...