DAO to ADO Migration Tips

By Q. Johnson
February 19, 2001

What I'm describing here

This is strictly changing from DAO to ADO for accessing JET database data. We're not doing any engine changes, too. And this is brief - not comprehensive, but I hope it will make your comprehensive study a lot less frustrating. At the risk of looking a little dim-witted by showing you how easily I fell victim to some mis-steps in learning this stuff, I hope to save you the same trouble.

Where to begin?

There are some very useful documents in the MSDN CD and finding some of them was a real chore. The most useful of the bunch (and one with jumps to the others) was:

Migrating from DAO to ADO
Using ADO with the Microsoft Jet Provider
Alyssa Henry
Microsoft Corporation
July 1999

Believe it or not, if you type "Migrating from DAO to ADO" into the search box on MSDN and tell it to search, this document comes up (at least for me in July 2000 version) as 23rd. Go figure. This one is in the Data Access Technical Articles area if you want to search for it manually on the contents tab. Some of the most useful information is presented in tabular form in the first two Appendices, but be sure and look at sample code.

The seventh item in that list (your mileage may vary) is the document to read first, though. It discusses whether the move even makes sense for you. This one is in the VB section of the Knowledge base and is described as:

INFO: Issues Migrating From DAO/Jet to ADO/Jet
ID: Q225048

That one warns you about the relative last of functionality of ADO for JET vs. DAO. It also talks about engine versions issues.well go see what it says. The bottom line is that you can't do everything with ADO that was possible in DAO. This paragraph should set the tone of your expectations: "The OLE DB Provider for Jet 4.0 exposes most of the Microsoft Jet functionality, but not all of it. In addition to the ADO type library, you must include references in your project to the ADOX and Jet and Replication Objects type libraries to take advantage of functionality outside the core ADO objects. This mainly falls into the category of manipulating Access-specific objects and some of the other issues noted below. " (I don't show those "other issues" here, but security is a pretty big part of it).

Some of the other useful documents (that I have in my Favorites list, to be sure!) are called ADO Object Model, ADOX Object model, Microsoft ADOX Programmer's Reference, and JET and Replication Objects.

Mapping the Object Transition

A lot of hype was devoted in VBPJ and elsewhere about how much simpler the object model is in ADO vs. DAO. Only three objects! And that is true; there are only three ADO objects (Connection, Command, and Recordset).

But the news is really quite sad because that means there is no equivalent to the Engine itself (for which you need access to Compact the DB and to force refreshing of the cache) or even the TableDef object or its collection to which you obviously need access in order to create or modify table structures in the database.

There's plenty of information around about how to open connections and command objects and recordsets and we don't need to spend any time there. The stuff works as advertised.

But the two new object libraries you will need to hunt and learn are those mentioned in that quoted paragraph.

ADOX is the "structure" library. The "X" in its name stands for the "Extensions for DDL and Security" in its longer name/description. The object model here is of a Catalog (the Database level object), its Tables collection of Table objects (our old TableDef friends) and the Table's Columns collection of Column objects (heaven forbid we should call them fields and confuse them with the very limited Field objects of the Recordset object in ADO proper). Some sample code is found for the ADOX stuff in the first document I mentioned above. Building tables looks like the old DAO technique - define the New Table, define New column objects and append them to the Columns collection of the Table and when you have them all, append the Table to the Tables collection of the catalog.

There are some very cool Provider-specific Column properties you can set, but you must set the .ParentCatalog property of the column in order to use them. This seems a bit counter-intuitive since the column has not even been appended to the table yet, nor the table to the catalog. But if you don't do this, ADOX has no way of knowing which Provider's properties you have access to. The sample code shows this if you look carefully enough for it (I did not on my first try, of course).

The Jet Object and Replication Library supports the JRO object. Even if you don't care one whit about Replication, you need the Engine object of this family in order to perform the CompactDatabase action and to idle the engine for `dbRefreshCache', as you likely recall from DAO. Read the help carefully on the CompactDatabase because you can get an unwanted "upgrade" to version 4.0 if you don't specify that you want it to stay in 3.x (assuming that is a concern for you). You also need to provide the security information in this call if your database is secured (Workgroup File Name, Logon Name, Password). So for a methods that has only two real arguments, this dude can get LONG.

Trying to implement the advice you find

In no particluar order:

None of these things would have bitten you? Great! Then please write up one of these for me for SQL Server and MSDE which I will be tackling in a couple of weeks.

Happy coding


Back to Articles
Copyright © 2000 by Matt E. Hart, All Rights Reserved Worldwide.
Nothing on this web site may be reproduced, in any form, without express written consent.