ActiveX Data Object (ADO) is Microsoft's latest data access object model. ADO 2.0 and Microsoft Data Access Component (MDAC) 2.0 are part of Microsoft's Universal Data Access (UDA) strategy.
Before you start working with ADO, we recommend you scope out http://www.microsoft.com/data. This site contains information about ADO, Object Linking and Embedding Database (OLE DB), OLE DB for online analytical processing (OLAP) Services, Open Database Connectivity (ODBC), Remote Data Service (RDS, formerly Advanced Data Connector), and UDA. Other resources include Jim Lewallen's "ADO Performance and Architecture" presentation from Microsoft's Professional Developers Conference (PDC) in 1998, and David Sussman and Alex Homer's ADO 2.0 Programmer's Reference (WROX).
Here are a few tips for working with ADO:
Don't be lazy. For example, avoid SELECT * FROM tablename queries, ask for only the columns you need, and use a WHERE clause to limit the number of records SQL Server returns. Describe command parameters yourself, because getting command parameter information is often as expensive as executing the command.
Use cursor-based updating only if you need it. Although using a SQL statement to update data isn't always feasible, do so when possible. Updating data through the RECORDSET object is easier than using SQL, but this process is more expensive.
If you want scrolling, don't default to server cursors. Microsoft set the ADO CursorLocation default to adUseServer primarily for backward compatibility. However, for most scrolling scenarios, you are better off using a client cursor.
When you know that query results will yield only one row of data, use a stored procedure with output parameters rather than opening a RECORDSET to fetch that data. A RECORDSET's query results include data and metadata, and the metadata is bigger and takes longer to retrieve than the data. Using a stored procedure is more efficient.
If you must use a cursor, use the COLLECT methods for singleton SELECT commands. The RECORDSET::GET_COLLECT and RECORDSET::PUT_COLLECT methods are RECORDSET object shortcuts that let you quickly receive and set a field value without first obtaining a field reference. Use the COLLECT methods when you don't need to obtain or set properties other than FIELD::VALUE.
If you know a query won't return any rows, use adExecuteNoRecords, ADO's new ExecuteOptionEnum option. This option causes ADO to avoid the overhead of both creating a RECORDSET and setting cursor properties.
Use CONNECTION::EXECUTE instead of RECORSDET::OPEN or COMMAND::EXECUTE for single execution of one-time commands, which is a fairly common scenario in Internet Information Server (IIS), Active Server Pages (ASP), and Microsoft Transaction Server (MTS) environments. In these environments, the code typically opens a connection, executes a row or non-row returning command, processes results, and closes the connection.
Use native OLE DB providers (drivers) whenever possible, but be selective about which drivers you use. SQL Server 7.0 ships with native providers for SQL Server and Oracle8. However, as Intersolv (vendors of DataDirect OLE DB drivers) explains, "The DataDirect Oracle8 OLE DB provider supports all the new Oracle8 data types and features rather than just access to Oracle8 servers. The Microsoft provider can connect to Oracle8 servers but doesn't support any of the new data types or features. For example, DataDirect allows access to binary large objects (BLOBs) and character large objects (CLOBs), but the Microsoft provider doesn't offer these features. Also, DataDirect supports other import features such as scrollable cursors and updatable rowsets, which the Microsoft provider doesn't support."
End of Article
You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor?
Register now
An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...
Let Your Users Reset Their Own Passwords: Free Download Try a 30 day free trial of Desktop Authority Password Self-Service – it provides an easy-to-use, robust system for allowing users to reset their own forgotten passwords or locked accounts.
Get Windows IT Pro & Mark Minasi’s Favorite Power Tools Guide Order Windows IT Pro now and get "More of Mark Minasi's Favorite Power Tools"--a in-depth guide to the most useful Windows commands --FREE with your paid order! Subscribe today, and save 58% off the cover price!
Deep Dive into VMware vSphere, eLearning Series Join John Savill to explore the major functionality capabilities of the vSphere virtualization platform, including identification of the changes from ESX 3.5.