数据访问的历史 Windows

节选:Programming Microsoft Visual Basic 6.0 1999
The Data Access Saga

All the new database-related capacities in Visual Basic 6 are based on Microsoft ActiveX Data Objects (ADO), a technology that lets you access any database or data source, as long as someone has written an OLE DB provider that connects to that source.

Figure 8-1 summarizes the many ways you can get to a data source in Visual Basic 6. As you can see, data access methods differ greatly in the number of layers that sit between your application and the database you‘re connecting to. In this book, however, I concentrate on ADO technology and give you only glimpses of the others. Deciding not to cover popular data access techniques such as DAO and RDO has been a difficult choice, but I had to make it to keep this book a reasonable size. I was comforted in this choice by the fact that DAO and RDO haven‘t been improved at all in Visual Basic 6; so if you already mastered those techniques in Visual Basic 5, there‘s nothing new for you to see. Both these older technologies will be eventually replaced by ADO. You can find several good books and other information sources about DAO and RDO, such as the superb Hitchhiker‘s Guide to Visual Basic and SQL Server by William R. Vaughn (Microsoft Press, 1998). Although I don‘t have the space to describe DAO and RDO in depth, you need at least a broad understanding of how they work. To help you understand the benefits that ADO brings you, I must describe the tools that were available before it and how ADO relates to those older technologies.

Figure 8-1. Accessing a database using ODBC, DAO, RDO, and ADO.

ODBC

ODBC stands for Open Database Connectivity and is a set of functions that lets you connect to a local or remote database. Microsoft launched this technology as a means of accessing several databases in different formats—dBASE, Microsoft FoxPro, Microsoft Access, Microsoft SQL Server, Oracle, or even plain comma-delimited text files—using a common API. The machine the application runs on connects to a DLL called the ODBC Driver Manager, which in turn sends commands to (and retrieves data from) an ODBC driver specific to the particular database you want to use. Visual Basic 2 was the first version of the language that was capable of connecting to an ODBC source. Since then the number of available ODBC drivers has grown very rapidly, to the point that it‘s nearly impossible to find a commercial database for which no ODBC driver exists.

The challenge of ODBC is to provide a common interface to all these different databases. In theory, you can prepare an application that uses ODBC to talk to an Access database and then upsize to an SQL Server database simply by changing the back-end ODBC driver and a few statements in the source code. You can do this because all the commands you send to the database are standard SQL statements. SQL (Structured Query Language) is a programming language specialized for working with databases. (See "Crash Course in SQL" later in this chapter for an introduction to SQL). In practice, however, while the ODBC layer does what it can to convert these standard SQL commands into the particular database‘s dialect, an ODBC programmer frequently has to bypass the ODBC translation engine and send commands directly to the database. (These are known as pass-through queries or commands.) Needless to say, having to do this hinders the portability of such an application to another database.

ODBC is efficient, at least compared with most other data access techniques. Another advantage of ODBC is that it supports both 16-bit and 32-bit APIs, so it‘s one of the few techniques available to Visual Basic 3 and Visual Basic 4/16 applications. ODBC version 3 has added several performance-boosting techniques, such as connection pooling, which means that an ODBC driver on the client side can reuse existing connections in a way that‘s transparent to your program. For example, your code can open and close multiple connections to a database, but the ODBC driver actually uses the same connection. Because opening a connection is a lengthy operation—it can take several seconds each time—connection pooling is bound to make your application much more responsive. Microsoft Transaction Server uses connection pooling to improve the performance of connections opened by ActiveX components that run under it.

Using ODBC, however, isn‘t easy, especially for Visual Basic programmers. The set of API functions is complex, and if you make a mistake you often crash your application with a fatal error. (If this occurs while you‘re in the IDE, you can‘t even save your code.) For this reason, relatively few Visual Basic programmers write applications that directly call ODBC functions. Interestingly, most other data access techniques available to Visual Basic can use ODBC drivers as intermediate layers, so sometimes you can augment other techniques (typically those based on RDO) with direct API calls. Unfortunately, you can‘t do that with ADO: Even though ADO internally uses an ODBC driver, you can‘t mix ADO code and ODBC API code for the same connection.

Even if you‘re not going to directly use ODBC API calls in your Visual Basic programs, you should become familiar with the basic concepts on which this technology is based. For example, one concept that you‘ll probably deal with even when working with ADO is the Data Source Name (DSN). A DSN is a set of values that an application needs to correctly connect to a database. It typically includes the name of the ODBC driver you want to use, the name of the machine that hosts the database server (if you‘re working with client-server engines such as SQL Server or Oracle), the name or path of the specific database, the timeout of the connection (that is, the number of seconds after which the ODBC driver gives up and returns an error to the calling application when trying to establish the connection), the name of the calling workstation and application, and so on.

You can create a DSN in several ways, inside or outside the Visual Basic 6 environment. The command center for ODBC is a Control Panel applet that lets you create DSNs and set other ODBC configuration values. You can choose from several types of DSNs. A User DSN is stored in the system Registry, can be used only by the current user, and can‘t therefore be shared with others. A System DSN is also stored in the Registry but is visible to all other users, including Microsoft Windows NT services. Finally, a File DSN is stored in a .dsn file and can be shared by all users (provided that the correct ODBC driver is installed on their machines). File DSNs can be easily copied on other machines, so they make the installation phase easier; on the other hand, the application needs to know where the DSN is located, so the code must provide the complete path to the .dsn file, and you need to store the path somewhere (in an INI file, for example). This is never an issue with User or System DSNs.

You aren‘t forced to work with DSNs if you don‘t want to. When you‘re working with ODBC, you can provide all the information needed for the connection—driver name, database name and path, and so on—right in your code. These are the so-called DSN-less connections, which are usually more efficient because you save the ODBC driver a trip to the Registry or to a File DSN. But DSN-less techniques require a bit more work from the developer.

The first three tabs of the ODBC Control Panel applet dialog box let you create, delete, and configure DSNs of all types. As you can see in Figure 8-2, creating a DSN often requires that you open several nested dialog boxes. The Drivers tab displays all the installed ODBC drivers and lets you compare version numbers (which is sometimes important when something doesn‘t work as expected on a customer‘s machine). Visual Basic 6 comes with several ODBC drivers (some of which are visible in Figure 8-3), but you can also purchase other drivers from third-party vendors.

You use the Tracing tab of the ODBC Data Source Administrator applet to define the path of the log file for all ODBC operations, which is a lifesaver when you‘re debugging ODBC-based applications. (This option is vital also when you are indirectly using ODBC through DAO, RDO, or ADO.) The latest version of the ODBC Data Source Administrator applet includes the ability to start Microsoft Visual Studio Analyzer, a tool that lets you monitor the activity of your programs over the network.

In the Connection Pooling tab, you can enable or disable connection pooling for each specific ODBC driver. You rarely need to change these settings, though, and I suggest that you not play with them unless you‘re pretty sure about what you‘re doing. Finally, in the About tab, you can check the position and versions of all the code DLLs of the ODBC subsystem.

Figure 8-2. Creating a User DSN for a Microsoft Jet database. The contents of nested dialog boxes depend on the ODBC driver you‘re connecting to.

Figure 8-3. Some of the ODBC drivers that can be installed by the Visual Basic 6 setup procedure.

DAO

DAO, or Data Access Objects, has a place in the heart of all programmers who began to develop database applications with Visual Basic 3. DAO is an object-oriented interface to Microsoft Jet, the engine that powers Access. Developers can design an MDB database using Access and then use DAO from a Visual Basic application to open the database, add and retrieve records, and manage transactions. The best thing about DAO is that it doesn‘t limit you to Jet databases because you can directly open any database for which an ODBC driver exists. Or you can use Jet attached tables, which are virtual tables that appear to belong to an MDB database but actually retrieve and store data in other ODBC sources.

Even if you can use DAO to access non-Jet sources, you can clearly see that it was devised with Access databases in mind. For example, even if your application doesn‘t use MDB databases, you still have to load the entire Jet engine DLL in memory. (And you also have to distribute it to your users). Even worse, DAO doesn‘t expose many of the capabilities that you could use if working directly with ODBC API functions. For example, you can‘t perform asynchronous queries or connections using DAO, nor can you work with multiple result sets.

Visual Basic 3 also contained the first release of the Data control. This control lets you bind one or more controls on a form to a data source and offers buttons for navigating through the records of the database table you‘ve connected to. At first, it seems that the Data control is a great tool because it lets you quickly create effective user interfaces to work with your data. After some testing, however, developers tend to abandon the Data control because its many limitations are difficult to overcome. Apart from performance considerations, the Data control has one serious disadvantage: It ties your front-end applications to the data in the back-end database. If you later want to access data in another database, you have to revise all the forms in your application. If you want to add complex validation rules to database fields, you must add code in every single module of the program. These (and other problems) are the typical defects of a 2-tier architecture, which in fact is being abandoned in favor of 3-tier (or n-tier) architectures, where one or more intermediate layers between the application and the database provide services such as data validation, business rules, workload balance, and security. Alas, if you want to embrace the n-tier philosophy, you should forget about the Data control.

Visual Basic 4 included the improved DAO 3.0 version, which features a special DLL that allows programmers who work with 32-bit technology to access 16-bit databases. Visual Basic 5 programmers can use DAO 3.5. In the Visual Basic 6 package, you‘ll find DAO 3.51, which is substantially similar to the previous one. This suggests that Microsoft doesn‘t plan to improve DAO further, even though version 4 has been announced for Microsoft Office 2000.

RDO

RDO, or Remote Data Objects, is the first attempt by Microsoft to combine the simplicity of DAO with the power of direct ODBC API programming. RDO is an object model vaguely patterned after DAO, but it bypasses the Jet Engine and the DAO DLL and works directly with the underlying ODBC drivers. Applications based on RDO load only a small DLL instead of the resource-hungry Jet engine. Even more important, RDO was specifically designed to work with ODBC sources, so it exposed functionality that couldn‘t be accessed from DAO. RDO is 32-bit technology, however, so you can‘t use it from 16-bit applications.

RDO 1 was introduced with Visual Basic 4, and the engine was improved in Visual Basic 5, which includes RDO 2. This latest version is a mature product and also supports a new programming model based on events, which is great for working with asynchronous operations. The development of RDO seems to have stopped, though, because Visual Basic 6 still includes version 2, with no apparent improvement over the version shipped with Visual Basic 5. So RDO could be another dead end. Although Microsoft seems committed to actively supporting RDO, it seems to be betting everything on ADO.

RDO 1 and 2 came with the RemoteData control, which works in much the same way as the Data control and lets you bind controls to remote data sources. In this sense, the RemoteData control shares all the advantages and disadvantages of the Data control, including its problems with n-tier architectures.

ODBCDirect

Visual Basic 5 included yet another data access technology, named ODBCDirect, which allowed programmers to employ RDO using a DAO syntax. ODBCDirect was conceived as a transition technique that would help Visual Basic programmers move their DAO/Jet applications to more powerful client/server architectures. In theory, by changing just a few properties, an existing DAO program that stores data in a Jet database might be converted to a client/server application that connects to any ODBC source. ODBCDirect shouldn‘t be regarded as a technology of its own. It‘s more like a trick that you can use to save time in converting applications, and nothing more. Most of the RDO 2 new features—the new event programming model, for example—can‘t be exploited by ODBCDirect because it has to be code-compatible with DAO. Besides, being based on RDO, ODBCDirect works only with 32-bit applications. For these reasons, unless you have very big and complex DAO/Jet Visual Basic applications to port to another database as quickly as possible, don‘t waste your time on ODBCDirect.

OLE DB

OLE DB is a low-level data access technology with which Microsoft intends to eventually replace ODBC as the primary means for connecting to databases. The OLE DB counterpart to ODBC drivers are the OLE DB providers, which work as bridges between applications and databases. Although OLE DB is a relatively recent technology, you can find OLE DB providers for most popular databases, and others will be released before long. In spite of their apparent similarities, ODBC and OLE DB technologies are profoundly different. First, OLE DB is based on COM, an architecture that has proven robust enough to move large quantities of data across the network. Second, OLE DB lends itself to the task of connecting any type of data source, not just relational and ISAM (indexed sequential access mode) databases, which are the natural field for ODBC drivers.

OLE DB is part of Microsoft‘s Universal Data Access (UDA) strategy, which enables you to read and process data where it is, without first converting it and importing it to a more traditional database. Using OLE DB providers, you can process data in e-mail messages, HTML pages, spreadsheet and text documents, and even in more exotic data sources. Visual Basic 6 itself comes with providers for Microsoft Jet, SQL Server, FoxPro, text files, and Oracle databases. You can download other OLE DB providers from the Microsoft Web site, and I‘ve heard of other providers from third-party vendors.

In the transition between the ODBC and the OLE DB worlds, you can use a special OLE DB provider, named MSDASQL—also known by its code name, Kagera—that works as a bridge to any ODBC source. Instead of connecting directly to the database, you can use this special provider to connect to an ODBC driver, which in turn reads and writes data in the database. This additional layer has a performance hit, of course, but you should look at it as a short-term solution to a problem that will disappear when more providers are available.

ADO

ADO is the high-level interface to OLE DB. It fills more or less the same role that RDO does for the ODBC APIs. Like ODBC APIs, OLE DB is a low-level interface that can‘t be easily (or at all) accessed from high-level languages such as Visual Basic. ADO builds on OLE DB to provide functions that aren‘t available directly in OLE DB or that would make stringent demands on the coding abilities of a programmer. ADO matches most of RDO‘s capacities: Both can make asynchronous queries and connections and optimistic batch updates. ADO adds great new features such as file-based and stand-alone Recordsets, hierarchical Recordsets, and more.

The single most important feature of ADO is probably its extensibility. Instead of being a complex and monolithic object hierarchy as DAO and RDO are, ADO consists of fewer objects that can be combined in more ways. New features can be added to ADO in the form of special OLE DB providers, such as the MSDataShape provider, which offers hierarchical Recordset objects to other providers. Microsoft also is making new features available in ADO in the form of separate libraries that link dynamically to the core ADO library. For example, the new ADO 2.1 library includes support for Data Definition Language and security (that is, the creation of new database tables, users, and groups of users), Jet replicas, and multidimensional Recordsets. Because these additions are distinct libraries, you don‘t have to distribute them with your applications if you don‘t use them. This contrasts with DAO and RDO, each of which comprises one larger DLL that embeds all the features (and which you have to distribute in its entirety even if you use a small fraction of its potential).

Another nice ADO feature is that you can use it from within HTML pages in a browser such as Internet Explorer or on a server inside an Active Server Page hosted on Internet Information Server. One ADO subsystem, named Remote Data Services, even lets you send a bunch of records to a client browser or activate COM components remotely over the Internet.

The only relevant defect of ADO is that it‘s a recent technology that hasn‘t proven its robustness in a large number of real-world applications, as DAO and RDO have. For example, I found a few bugs in ADO 2, even though my experience is that most of these problems were caused by the OLE DB provider, not ADO itself. This distinction is important because you can often fix these bugs by simply updating the provider when a new version is released. In fact, I found that the providers for Microsoft Jet 4.0 and SQL Server 7.0 are noticeably better than the versions for Jet 3.51 and SQL Server 6.5. (The latter are the providers distributed with Visual Basic 6.) I expect that by the time you read this book, most major problems with ADO will be fixed. On the other hand, the only alternative to ADO is to continue to use DAO or RDO, but, as I‘ve explained, these technologies aren‘t going to be improved significantly in the future.

You can see that choosing the data access technique to use is a complex matter. My suggestion is simple, though: If you‘re maintaining or updating an existing application based on DAO or RDO (or ODBC APIs, if you‘re a brave programmer), wait until you see where ADO is going. If you‘re beginning a new application, give ADO a try, especially if you plan to update and maintain it for several years or if you plan to eventually port it to the Internet.

The good news is that Visual Basic 6 includes several tools and facilities for creating ADO applications quickly and effectively. For this reason, the rest of this book focuses on ADO exclusively.

时间: 2024-08-15 17:25:11

数据访问的历史 Windows的相关文章

十步优化SQL Server中的数据访问(转载)

原文地址:http://tech.it168.com/a2009/1125/814/000000814758.shtml 故事开篇:你和你的团队经过不懈努力,终于使网站成功上线,刚开始时,注册用户较少,网站性能表现不错,但随着注册用户的增多,访问速度开始变慢,一些用户开始发来邮件表示抗议,事情变得越来越糟,为了留住用户,你开始着手调查访问变慢的原因. 经过紧张的调查,你发现问题出在数据库上,当应用程序尝试访问/更新数据时,数据库执行得相当慢,再次深入调查数据库后,你发现数据库表增长得很大,有些表

【7】AccessDB快速数据访问

阅读目录 C#和VB数据访问的比较 AccessDB的设计 数据库的连接 三种主要操作 错误输出及调试 小结 回到顶部 C#和VB数据访问的比较 C#中要进行一次普通的数据库查询,需要创建连接,再根据具体的数据库类型,创建相关的适配器对象,再创建命令对象,执行后,将结果填入到Dataset中,用户拿到Dataset后,再从其中的DataTable中取得数据.这种处理方式存在种种不便之处: 1.需要一系列复杂操作才能完成一个简单功能,涉及的对象多.实现的逻辑和自然的思维习惯有所不同. 2.对不同类

微软-创建数据访问层

简介 https://msdn.microsoft.com/zh-cn/cc964016 作为web 开发人员,我们的工作总是在和数据打交道.我们创建数据库来存储数据,编写代码来检索并修改数据,并创建Web 页面来收集和汇总数据.这是探讨在ASP.NET 2.0 中实现这些常用类型的技巧的系列教程中的首篇教程.我们从创建一个 软件架构 开始,包括使用Typed DataSet 的数据访问层(DAL) .实现自定义业务规则的业务逻辑层(BLL) 和共享同一页面布局的ASP.NET 页面组成的表示层

Windows Server 2008R2配置MySQL Cluster并将管理节点和数据节点配置成windows服务

说明:将mysql的管理节点和数据节点配置成windows服务是为了防止有人手误关闭管理节点或数据节点的dos命令窗口,管理节点或数据节点的命令窗口误关闭可能会造成mysql某台或某几台mysql不能被访问,注册成windows服务自动启动更安全可靠. 目录 操作系统:Windows Server 2008 R2 Enterprise VM1:192.168.220.103 管理节点(MGM), VM2:192.168.220.104数据节点(NDBD1),SQL节点(SQL1) VM3:192

Oracle数据访问组件ODAC的安装方法

Oracle数据访问组件ODAC(Oracle Data Access Components)顾名思义就是用来访问Oracle数据库的小程序.我们可以编程调用这些组件来实现在没有安装Oracle数据库软件的电脑上完成对Oracle数据库的访问. 工具/原料 ODAC安装包 步骤1. 下载ODAC安装包 到Oracle官方网站下载ODAC安装包.在网页上找到你要的版本.我下载的是: 64-bit ODAC 11.2 Release 6 (11.2.0.4.0) Xcopy for Windows

[翻译]比较ADO.NET中的不同数据访问技术(Performance Comparison:Data Access Techniques)

Performance Comparison: Data Access Techniques Priya DhawanMicrosoft Developer Network January 2002 原文链接:https://msdn.microsoft.com/en-us/library/ms978388.aspx 概要:在典型的应用环境中,比较不同数据访问技术的表现性能.适用于Microsoft .NET Framework Beta2 和 Microsoft SQL Server 2000

.net数据访问层组件Data Abstract 免费下载及使用方法大全

原文来自龙博方案网http://www.fanganwang.com/product/1321.com/转载请注明出处 Data Abstract是最好的多层次框架,它提供端到端的解决方案,同时也可以很轻松地建立起可扩展的数据库方案以满足如今的分布式系统要求. 概况特性 ·         为.NET,Mono,32/64位的Windows以及Linux建立可扩展的.跨平台的多层次数据库解决方案. ·         使用一个通用的代码库处理不同的数据库设计或数据库系统. ·         使

多线程编程之数据访问互斥

在多线程存在的环境中,除了堆栈中的临时数据之外,所有的数据都是共享的.如果我们需要线程之间正确地运行,那么务必需要保证公共数据的执行和计算是正确的.简单一点说,就是保证数据在执行的时候必须是互斥的.否则,如果两个或者多个线程在同一时刻对数据进行了操作,那么后果是不可想象的. 保证多线程之间的数据访问互斥,有以下四类方法: (1)关中断 (2)数学互斥方法 (3)操作系统提供的互斥方法 (4)CPU原子操作 下面针对这四种方法进行详细说明: (1)关中断 既然多线程之间的中断切换会导致访问同一数据

重要!!!实体类、数据访问类

创建两个类: users类: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 实体类_数据访问类.App_Code { public class Users { private int _Ids; /// <summary> /// ids /// </summary> public int Ids { get { return _Ids;