|
Over the last six years or so, Microsoft has been driven by customer demand to release an ever-expanding series of data access interfaces for Microsoft Visual Basic. Beginning with the Visual Basic Library for Microsoft SQL Server (VBSQL) and ending with the most recent interface to OLE DB, ActiveX Data Objects (ADO), a new data access interface seems to evolve every couple of years. As you've seen in earlier chapters of this guide, each of these interfaces addresses broadening customer requirements to access an ever-increasing number of data sources. As Visual Basic applications have grown more sophisticated and data-centric, so have the data access interfaces. But now, we're faced with a dizzying variety of data sources. Choosing the right one is harder than picking out just the right gift after having overlooked your thirtieth wedding anniversary. Been there, done that. No thanks.
It's not unusual these days to find businesses that want to access databases, mail, directory, telephony, exotic, legacy data, or Internet contentall from the same application or system. The problem is that each of these data sources has its own proprietary or merely different data access interfaceif an interface exists at all. Some require API access, others can be accessed by using one of the more familiar data access paradigms. This cornucopia of data sources means that the skills you've learned to access one type of data don't always apply to other types. It also means that once the data arrives it must be morphed into some common format, or your applications have to adapt themselves to the different structures and data access interface requirements. Figure 28-1 shows an application that needs to draw from a wide variety of data sourcesno two of which use the same data access interface. In this figure, notice that the application uses at least five separate APIs to access the different types of data. Some of the interfaces are Component Object Model (COM) interfaces, and some are not; some expose Automation (formerly known as OLE Automation), interfaces; and some are procedural. In addition, transactional control doesn't exist, so I can't safely make any changes to all the information within one transaction.
Figure 28-1 What all of this means is that the developers who write the application will have to become experts in a multitude of data access methods. Is there a better way? Well, one solution is to put all the different types of data into a single relational data store. That is, take the relational data, the ISAM data, e-mail data, directory data, and any other information, including that from the Internet, and move it into a single relational database. This approach solves the problem of having a single API or interface that also gives you transactional control, but it has a number of problems. First, this all-in-one approach requires moving huge amounts of data out of the original source(s). Second, you typically don't own much of the data you need, such as the wealth of information on the Internet or the data from that rogue accounting department upstairs. Sure, you could get a copy of it todaybut that information would soon be stale and have to be refreshed, and you would have to repeat the download or at least keep a replication engine running full time. The third problem with moving the data into a single data store is that tools today don't look for or store data into a single relational data store. E-mail applications, word processors, project management tools, spreadsheets, Web sites, and other tools expect to access their own data stores for their data. You would have to rewrite your tools to access the data in the single data store or duplicate the data to the single data store from where it naturally livesthen you still run into problems with synchronizing the data. A fourth problem is that one size does not fit all. The way that relational databases deal with data is not the best way to deal with all types of data. Data (structured, semistructured, and unstructured) is stored in different containers based on how the data is used, viewed, managed, and accessed. It's like trying to store earth, wind, fire, and love in plastic buckets. Finally, the performance and query requirements are going to differ by data type, depending on what it is you're trying to do. Ah, no. This approach is not your best solution. Go back three squares, and start over. Of course, those of you out there who have tried this approach (at least to some extent) know what I'm talking about.
In fall 1996, Microsoft introduced the inaugural version of its answer to this complex problem. The strategy has since been dubbed Universal Data Access. In theory, this strategy provides access to all types of data through a single data access modelwith OLE DB and ADO at the center. With Universal Data Access, you can access data in different data stores through a common set of interfaces, regardless of where the data resides or what form it takes. No, at this point, an OLE DB data provider for earth, wind, fire, or love is not availablebut they're working on it. Implementing this architecture, your Universal Data Access application speaks to a common set of interfaces that generalize the concept of data. Microsoft examined the common characteristics of all types of data, such as how you navigate, represent, bind, use, filter, sort, and share that data with other components. The result is a set of interfaces that developers can use to represent data kept in relational databases, word processors, spreadsheets, and applications of all kinds, and in project and document containers, ISAM, email, and file systemsvirtually all forms of information. The data stores simply expose common interfacesa common data access modelto the data. With this Universal Data Access strategy in place, our application now looks like the model shown in Figure 28-2.
Figure 28-2 If you want to find out more about the Universal Data Access paradigm, see /data/.
ADO is the newest data access interfaceit is the "Automation server," or object-level interface, to OLE DB, which is a new low-level object-based interface. OLE DB is included in the new bundle of tools dubbed the Microsoft Data Access Components (MDAC) data access paradigm. Sound familiar? Yes, these are almost the same terms that were used to describe Microsoft's Open Database Connectivity (ODBC) some years back. However, OLE DB's architecture is not restricted to ISAM, Microsoft Jet, or even relational data sources, but is designed to interface with virtually any type of datainformationregardless of its format or storage method. OLE DB doesn't really do anythingit defines what its service components and data providers must do and provides standard ways to expose that functionality to developers. IMHO Microsoft should stop and let the industry take a breather. I think we should let the engineers refine what's already in place and make sure it's workingbefore adding any more new features. We should now just build data providers for more data sources and fix bugs. Unfortunately, Microsoft thinks that if it stops innovating for a single minute, some hotshot startup company will take over the industry with a new whatsit and all will be lost. Personally, I don't think the development community is that fickle. I think it would take at least a week or two for a startup company to overtake Microsoft. OLE DB also means something else. I grasped the impact of this "something else" only when I tripped over a Web site listing all the new OLE DB service components provided by companies other than Microsoft. This third-party support means that developers will be able to choose from a wide variety of independently created OLE DB service components, ranging from hierarchical data and heterogeneous join engines to interfaces against exotic data sources. The bad news is that you can't access OLE DB directly from Visual Basic 6.0 because of OLE DB's complex interfaces. The good news is that ADO exposes virtually all of OLE DB's functionalityso Visual Basic developers don't really need to be concerned about that limitation. But the rest of the bad news is that ADO imposes another layer that C++ applications don't require. OLE DB provides data integration over an enterprise's networkfrom mainframe to desktopregardless of the data structures involved. Microsoft's ODBC, the reigning industry-standard data access interface, continues to provide a unified way to access relational data as part of the OLE DB specification. Over time, OLE DB is expected to replace ODBC as the standard low-level interface to data. Figure 28-3 shows you what the OLE DB architecture looks like. As you can see in Figure 28-3, OLE DB is no more complex (on the surface) than ODBC. It uses replaceable service components and data providers to permit access to a variety of data sources through a common API. The service components munge data in a variety of ways. For example, the service components layer is where the various cursor, hierarchy, and heterogeneous join engines run. You can load whatever services you need and leave the rest out of memory until they are needed. The service components also fill in where data providers don't or can't provide needed functionality. You choose the features you need. The data providers know how to access a chosen data source. Data providers can even access ODBC data source drivers. In short, OLE DB's architecture provides a flexible and efficient database interface that offers applications, compilers, and other database providers efficient access to Microsoft and third-party data stores. NOTE After I'd finished writing the ADO chapters, the product managers at Microsoft informed me that they had decided to change the name of OLE DB service "providers" to OLE DB service "components." This terminology was changed to reduce the confusion between "data" providers (basically the database interfaces) and the data munging engines such as cursors, filters, and sorters.
Figure 28-3 OLE DB is a freely published specification designed with industry-wide participation through Microsoft's Open Process. OLE DB should provide consistency and interoperability in an enterprise's network, from the mainframe to the desktop and across the Internet. OLE DB is the fundamental COM building block for storing and retrieving data and unifies Microsoft's strategy for information access. It will be used throughout Microsoft's line of applications and data stores. Although OLE DB has been accepted by a large number of third-party ISVs, its overall acceptance in the industry remains to be realized.
As I said before, OLE DB has been designed to eventually provide superset functionality over ODBC. Will it replace ODBC anytime soon? I doubt itit's too busy catching up. In addition, there is simply too much Data Access Objects (DAO) and Remote Data Objects (RDO) code interwoven into the fabric of today's data access applications for this shift to happen overnight. ODBC will continue to provide a unified way to access relational dataeven as part of the OLE DB specification. OLE DB is currently able to leverage existing ODBC drivers because there is an OLE DB provider for ODBC, which eliminates the need for the intermediary ODBC Driver Manager. What does OLE DB do that ODBC doesn't? If you're accessing a wide variety of data from a COM environment, OLE DB (via ADO) is your best choice because it goes beyond relational data access methods. And because OLE DB uses COM and can be used with Remote Data Services (RDS), OLE DB is better suited for the Internet and can take advantage of features in COM such as cross-process notifications. In addition, OLE DB lowers the barriers for data access more than ODBC does. An ODBC data source must provide functionality equivalent to a SQL query in order to expose its data. In OLE DB, it is possible for simple, non-SQL data sources to expose their data very efficiently without the need for a complex SQL processor. NOTE OLE DB will be able to use Distributed COM (DCOM) in SQL Server 7.0 to communicate with osystem components and data sources. IMHO I came back to this chapter after having spent about three weeks straight working on OLE DB and ADO code when it suddenly struck me that the specifications were somewhat odd. I got the distinct impression that they were written from the point of view of someone writing a service component or data providernot based on what you, the Visual Basic developer, would want to see when using ADO. Over and over, I saw the sentence, "This functionality might not be implemented by your service provider." The spec included numerous references to things the provider "should" implementleaving lots of flexibility open for interpretation and innovation. That's not all that bad. However, this approach means that developers trying to use, support, or deploy ADO are going to find it far more difficult to gain this "universal" level of compatibility among data sources (er, service components) than ever before. This kind of flexibility breeds incompatibility. In response to this problem, the Microsoft Data Access team is setting up a program to certify OLE DB service components and data providers. Will that make it easier for ADO and Visual Basic developers? We'll see. Is ODBC 3.0 required for compatibility with OLE DB? Nope. Microsoft supports existing ODBC drivers. However, I've seen some mail that indicates there are compatibility problems with ADO 1.5 and certain ODBC driversbut I expect this problem is transitory. You'll have a heck of a time keeping ODBC 3.x off your systems though. Microsoft Internet Explorer 4.01, Microsoft Office, Visual Basic, and every application from here to Detroit installs it nowadays.
SQL Server 7.0 is adding considerable functionality based on the OLE DB specification, and it is doing so in two ways. First, SQL Server 7.0 exposes a native OLE DB provider for SQL Server (SQLOLEDB.DLL) in addition to its existing ODBC and DB-Library interfaces. Second, SQL Server acts as an OLE DB "consumer" when it needs to get data from other data sources. Why does this make sense, you ask? Well, the SQL Server team wants to provide standard, COM-based access to SQL Server data as well as enable access to more kinds of heterogeneous, possibly distributed, data sources from within the SQL Server query processor. SQL Server will be able to do heterogeneous joins and perform far more complex operations on far more types of databesides its own native formats. Have you ever wanted to do a join from a Microsoft Access or DB2 table with your SQL Server database and do it on SQL Server? Now you can. Now SQL Server is not only a data provider, but a consumer as well.
One of the nuances that might have escaped the casual reader is the fact that OLE DB and ADO have introduced a number of new architectures. Although these architectures have been evolving over the last year or so, they are new to many of us. In this section, I'm going map these out so that we can see where OLE DB and ADO fit into the bigger picture. I see the architectures that use OLE DB broken down into several differentbut interrelatedapproaches to data access. Some architectures involve the Internet, many don't. Some involve "permanent" connections, others connect only as needed. Most involve some amount of server-side code, but not all involve client-side code. IMHO Unfortunately, the OLE DB provider for ODBC, referred to as "Kagera," makes a number of rather rude assumptions about how one should behave when opening or closing an ADO Recordset. This and other problems make me think that when building ADO applications, developers should probably hasten their migration to "native" OLE DB components rather than depend on ODBC to do the job. We'll discuss these bizarre connection issues later in this section.
IMHO Swell, we have yet another "native" interface. Actually, SQL 7.0 no longer considers DB-Library a fully supported native interface. It's supported, just not completely, because it wasn't updated from its SQL 6.5 version. One of the problems we're having to address with diverse systems is called reach. A program with reach is designed to run on (or at least be able to send data to) a wide set of platforms. More and more, we're encountering a cacophony of terminals, PCs, browsers, and bottom feeders that are our target client systems. Even when we create an application for a small business, the chances of all the systems being the same are probably 80/20. Pretty good odds. As the business grows, however, the odds of a uniform solution evaporate as other, incompatible clients are brought in. Although Microsoft Windows clients constitute 90-some percent of the clients out there, not all of them are running 32-bit Windows or Microsoft Windows NTand only about half of them are running Internet Explorer. If you have a completely uniform set of target client systems, count yourself lucky. Take a week off and go to Vegas to cash in on your good fortune. By the time you return, your management will have purchased another company with 50 Atari 800 systems that have to be accessed by your new application. Some companies feel blessed simply if all their client systems run on electricity. Welcome to life in the fast lane. OK, now that we know why these architectures need to exist, let's see how ADO and OLE DB address the various platforms. To do so, we need to consider what the environments look like. For the purposes of this discussion, I must narrow the focus to architectures that access SQL Serverotherwise, you'd still be reading this chapter when you were supposed to be out Christmas shopping for that perfect end-of-the-millennium gift.
We start with our traditional client/server rig, as illustrated in Figure 28-4. We've gone over this setup before in the early chapters, so this review will be brief. In a traditional client/server system, we have a 32-bit Windows client running a Visual Basic application using RDO or ADO. These applications depend on a constantly available "persistent" local area network (LAN) or at least a dial-up Remote Access Service (RAS) connection. We use server-side stored procedures, and we can migrate some of the business logic off of the client and on to the server using rules and triggers.
Figure 28-4 OK, what if your customer also has some 16-bit Windows clients? This scenario isn't that atypical, so we need to consider it for this configuration. In this case, you would have to use Visual Basic 3.0 or 4.0 (16 bit) and DAO or VBSQL on the clients. Such a motley system would be possible to implement, but messy and expensive to deploy and support.
At this point, you might have considered using Remote Automation for your 16-bit clients and calling remote COM components on a 32-bit server running Microsoft Transaction Server (MTS). But that seems like an awful lot of trouble. So what are your alternatives now? As it turns out, while you went out for lunch this afternoon, your company bought a competitor who didn't make the same design choices you did. This now-defunct company chose to use Netscape for its 16-bit Windows clients and brought over a handful of old Macintosh systems as well. It used to have some Sun boxes, but those were left behind to use as doorstops. So you consider the next alternative: Web-based architecture. HTML implementation Well, you certainly should entertain a pure HTML solution. This design generates HTML on the host and lets the client choose from static pages, or it supports the generation of dynamic pages based on options or arguments provided by the client. Does choosing an HTML solution mean you have to give up ADO? Hardly. By using ASP pages on IIS, you can still use a pure HTML interface with your clients and keep your ADO codeor at least parts of it. ASP implementation You can use Microsoft Internet Information Server (IIS) to run ADO code embedded in Visual Basic, Scripting Edition (VBScript) on an Active Server Pages (ASP) page. ASP pages are managed by IIS, which opens the selected page and runs it like an interpreted programkinda like running Quick Basic by remote control. (You probably run into ASP pages all the time without knowing it. Just look for the ASP extension the next time you use your browser.) If IIS finds embedded VBScript code in the ASP page, it invokes the VBScript interpreter to run it. Depending on your browser's capability, this code can have VBScript and ADO logic that can query a database and generate a Recordset to return to the browseror it might just return pure HTML. Figure 28-5 shows a sample of this architecture. RDS implementation ADO really outshines the other alternatives when it comes to working with the Web. The reason ADO is such a brilliant Web interface is that it's capable of generating and managing disconnected (remote) Recordset objects using RDS. RDS is already built into Internet Explorer 4, which makes it fairly easy to use (no need to download more code). Sure, Netscape supports HTML generated by VBScript on ASP pages, but it has none of the client-side RDS functionality. RDS applications embed VBScript code into selected Web pages and draw on considerable client-side functionality to extract data from a remote server.
Figure 28-5 NOTE RDS has now been integrated with ADO to provide data remoting within the same model as ADO. This integration makes it easier to design, code, and deploy both Web-based and LAN-based applications. RDS goes beyond the current generation of Web data access tools by allowing clients to manipulate the data they see. RDS technology uses both client-side and server-side RDS components to permit your application to run a query on a remote server. You can submit a request, and the client-side RDS components will send the query. The server-side RDS components will request the data from the data source via ADO and OLE DB and return the results to the client. The result set is returned to bound controls (like a grid). You can change the data in (some of) these bound controls, and you can submit updates, which posts changes back to the database. Figure 28-6 shows this process in which the client-side RDS components act like a Web-page-based Data control to connect an OLE DB data source to the client. It does this by sending and receiving HTTP requests and responses over the wire. Internet Explorer 3.0 or 4.0 is required to support RDS. Nope, it's not likely that Netscape will support the RDS technologyunless some government edict makes them. Stranger things have happened. NOTE Yep, Microsoft renamed Advanced Data Connector (ADC) to Remote Data Services (RDS). Why? BHOM. WebClass implementation The newest member of the Visual Basic data access team is a technology that permits you to create Visual Basic components that run on the middle tier. These components, called WebClasses, can be debugged interactively, and they can output HTML. This innovation is called WebClass application development. As you can see in Figure 28-7, creating a typical WebClass application follows the traditional form-based development paradigm you're used to.
Figure 28-6 With Visual Basic WebClasses, the code you write runs on the servereither interpreted or in binary form. The ease and simplicity of this model have been extended to server-executed applications that deliver an HTML interface to the client. In the WebClass application model, a Web page is first created using an editor such as Microsoft FrontPage 98 or Microsoft Visual InterDev 6.0 and then loaded into the designer. This means that the presentation and user interface experts on your team will decide on the visual aspects of the program. Then it's your turn. At this point, you write code to respond to an event, typically the clicking of a Submit button. Finally, just as in a traditional Visual Basic application, you can execute the application at design time, interactively debug the code, and then deploy it. Well, the deployment part is different. You simply point to an ASP page that launches the WebClass application components.
Figure 28-7 The differences between a WebClass application and a traditional Visual Basic application are significant. First, you'll need a browser to deal with the HTML (or Dynamic HTML). No, you don't create any binaries to run on the user's systemnot unless you want to. So your application can be executed by any HTML browser. Second, users interact with the application by clicking on a link or typing a URL into the browser. Finally, and most important, all the application logic can exist in server-side code, which simply returns HTML, XML, or other MIME types that are tailored for the requesting client. Thus a client doesn't need to install a WebClass application. At its core, a WebClass application is a standard COM object that resides on a Web server and responds to incoming HTTP requests from a browser. Architecturally, a WebClass is a container for an application's subroutines, functions, methods, and events that communicate over the Internet. At run time, an ASP page hosts the WebClass, allowing the IIS application to take advantage of the same functionality available within scripted ASP pages, such as built-in session management and request-response objects. You can create a WebClass application by starting an IIS Application project, or you can add a WebClass as a module to existing DLL projects. Figure 28-8 shows an architecture that uses WebClasses.
Figure 28-8 All these Web-centric architectures support ADO for data accessand we didn't even get into the DCOM architectures. ADO also lends itself very nicely to Visual Basic components run by MTS. The point of this little side trip? Well, in part, I thought you should see how flexible ADO has become. It has matured well beyond the experimental interface that first appeared in IIS in the winter of 1996-1997. NOTE Folks, I haven't even begun to show you all the ways you can build Web applications with Visual BasicI haven't even come close. This book isn't really the place to go into much depth on the subject, however; suffice it to say that you have a lot of new options when it comes to building Web-based systems. Ah yes, more choices. Hazzah. A First Peek at ADOIn this section, we're going to drill down into the stuff that ADO is made of. As you should know by now (unless you came in late), ActiveX Data Objects (ADO) is the object-based interface to OLE DB. By using this new data access interface, which in some ways resembles DAO and RDO, developers can now access an even broader variety of data sourcesusing both OLE DB data providers and existing ODBC data sources through its OLE DB to ODBC bridge.
Last Updated: Friday, July 6, 2001 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||