Is it better to use ADO or DAO in Access 2007? - vba

When creating a new database in Access 2007, should ADO (ActiveX Data Objects) or DAO (Data Access Objects) be used?
Edit: Part of this database will be importing data from Excel 2007 spreadsheets.

[For the record, the official name for what once was 'Jet' is now the 'Access database engine'.]
For ACE (the Access2007 engine .accdb format) features it has to be ACEDAO.
For Jet 4.0 features it has to be ADO classic.
For Jet 3.51 features and earlier, pick either ADO or DAO. There are advantages and disadvantages to both. The vast majority of Access database engine functionality is common to both; the mutually exclusive functionality is arguable fringe. A lifestyle choice, perhaps, but no big deal. The smart coder uses the best of both :)
I've used both quite a bit and ADO is my personal preference. It is more modern than DAO, so architecturally it is an improvement: flatter object model, none of the tear down problems of DAO, etc. More properties and methods and introduces events (DAO has none) e.g. for asynchronous connection and fetching of records. ADO recordsets can be disconnected, hierarchical and fabricated, DAO recordsets cannot. Basically, they took the good things about DAO and made them better.
DAO is not without its strong points. For one, you will find more DAO code examples than ADO for Access/Jet.
P.S. for some reason, folk who like DAO really dislike ADO. Ignore the propaganda. ADO isn't deprecated. The ACE has an OLE DB provider and is currently the only way of using ACE in 64 bit. ADO.NET hasn't replaced ADO classic any more than VB.NET has replaced VBA6 in Access projects.
EDIT: just to clarify, "For Jet 4.0 features it has to be ADO classic," this is because DAO 3.6 only received a few enhancements for the features new to Jet 4.0. For example, for the DECIMAL data type you cannot specify scale/precision. Other features are missing completely from DAO. For example, can you do the following in Jet 4.0 using DAO (or ACEDAO in ACE for that matter)?
CREATE TABLE Test (
col1 CHAR(4) WITH COMPRESSION DEFAULT '0000' NOT NULL,
CHECK (NOT EXISTS (
SELECT T1.col1
FROM Test AS T1
WHERE T1.col1 <> '0000'
GROUP
BY T1.col1
HAVING COUNT(*) > 1
))
);
(hint: compressible fixed-width text column with table-level data integrity constraint.) No, you cannot.
AFAIK the only enhancements to ACEDAO was for the new ACE functionality i.e. they didn't go back and fill in the Jet 4.0 gaps in DAO. And why should they? We still have ADO to plug the gaps. Better that the team spent their time more productively, like fixing that annoying DECIMAL sort bug, for me the best thing about ACE ;-)

DAO is the is the recommended technology here. ADO has much been depreciated, and is now being replaced with ADO.net.
Not only is DAO the native and recommended data object model for using MS access, it continues to be enhanced and now has a whole bunch of new features for sharepoint. In access 2007 we now have Support for SharePoint lists. This means that new DAO object model for 2007 allows a sharepoint list to be used and viewed as a SQL server table. That means you can use SQL on sharepoint lists (in fac there not even a oleDB provider that allows you to use SharePoint lists this way, but with DAO you can now do this). There is nothing of this sort that been added to ADO. So SharePoint lists from a access (dao) point of view sees these SharePoint lists as a standard table.
Furthermore DAO in access also has support for what we call complex data types. This was done to support XML lists from sharepoint. Keep in mind for the next version of access (2010) we are going to see a whole bunch more new additional features being added to DAO (JET is now called ACE).
So it is without question that DAO is the correct and good model to use. ADO is not receiving any more enhancements, and has been superseded by ADO.NET.
So the future belongs to DAO, and it’s clear that’s where Microsoft is investing its money in terms of MS access and terms of upgrading Access to work with things sharepoint.
Access 2007 received multi-value capabilities for its field definitions, and again this was a result of enhancements for supporting sharepoint. However, these features are part of JET and these enhancements can be used without sharepoint. they are now part of DAO.
edit:
Perhaps I’m going to expand on this a little bit, and try to clarify what we have such opposing answers here, I can assure you that when using access 2007, you’re far better off to use DAO.
Where the confusion stems from, is if you look of the tools references when you choose to use the default data object model access 2007, the problem here is it’s not called DAO anymore. It is now called ACE.
When you use DAO in access 2007 You’ll note in the tool references, the reference is not set to DAO 3.6 ( that version has been depreciated, and also is now not part of MDAC download anymore). You’ll notice that the new reference when using DAO in ms-access is called:
Microsoft office 12.0 access database engine Object Library
Now the above is a bit of a mouth full, but the above is the correct for reference access 2007 when you’re going to use DAO in place of ADO.
In other words, perhaps we should call this DAO II.
In other words, this data engine continues to be enhanced, and will most assuredly see a 64 bit version of this engine for office 2010 (office 14).
So the question or confusion centers around what term were going to use when we refer to using DAO in access 2007. The confusion here is in fact that the documentation and even the tools ->reference does not call it DAO.
At the end of the day in access 2007, if you plan to use DAO then that means that you set the above reference, and do not set a reference to DAO 3.6. Regardless, it makes absolutely no sense to start using ADO now when it’s been depreciated, and the new DAO object model for access continues to be enhanced and invested in by Microsoft.
I hope this helps in clearing up the confusing here. While DAO/JET It’s being depreciated, the new version access 2007 is based on the same code base, except it continues to get enhanced. So the new data engine in access can be considered and called the new DAO object model.
I’m currently under NDA on this issue, but I can most surely tell you that for the next version of office (2010) we are going to see a whole slew of enhancements again.
So it is near unanimous among Access developers that when developing access applications and using the native data engine, the preference here is to use the DAO object model ( but keep in mind we’re not calling it that anymore, we called it ACE).

The answer to the question depends on what you're doing. If you're using Access to work with data that's in a format whose ADO interface is more versatile, then use ADO. If you're using Jet data, or using the Jet database engine to work with another database engine (via ODBC), then DAO is the right choice.
But that answer assumes you're working from Access. If you're working from some other programming environment, the answers will likely be completely different.

It depends on your needs. Neither tool is expected to disappear soon.
If you don't have experience in either ADO or DAO, you'll find DAO is much, much easier. So unless you need ADO, use DAO.
You added this critical item: "I'm trying to pull in data from an external source into an Access DB." This connectivity may require ADO.

ADO is the current recommended access method. I think DAO has been deprecated for quite a number of years.
Looks like its been since Access 2000 - according to this link,
List of obsolete data access technologies - http://msdn.microsoft.com/en-us/library/ms810810.aspx#mdac technologies road map old_topic9
Quote from the above article, which was revised Dec 2008 - "Data Access Objects (DAO): DAO provides access to JET (Access) databases. This API can be used from Microsoft Visual Basic, Microsoft Visual C++, and scripting languages. It was included with Microsoft Office 2000 and Office XP. DAO 3.6 is the final version of this technology. It will not be available on the 64-bit Windows operating system."

DAO just rocks in terms of performance compared to ADO. There's no comparison.

Apologies that this is an answer, when it should have been a comment (I do not have the rep), but I wanted to clear up an erroneous claim that DAO/ACEDAO does not support Jet 4.0 record-locking. It does, and that is the default behaviour, irrespective of what certain MS articles claim.
The problem is this may introduce huge bloat (hugely fragmented DB file) when using DAO edit/update and you cannot turn it off in DAO/ACEDAO.
If you do have this issue, you can turn it off via first opening the database via an OLEDB connection using the correct Jet OLEDB:Database Locking Mode settings, which will allow you to set the database to page-level locking. This property will then be respected by consequent connections, DAO or otherwise, so you can then use DAO for fast updates etc.
This will then allow DAO to revert to the usual 8X performance compared to executing SQL statements.
Here are a couple of links pointing to the issue:
Does ACEDAO support row level locking?
http://www.access-programmers.co.uk/forums/showthread.php?t=47040
MS KB article, including code of setting locking mode with ADO, then using DAO on that DB - http://support.microsoft.com/?id=306435

Related

Display a DAO table in a form

I'm upgrading an old VB6 application to VB.NET that uses DAO to connect to an Access database. I know that this is a hopelessly outdated technology, but considering the amount of work changing to ADO, I've decided to stay with DAO, despite the frustration trying to find documentation.
My problem is that I'd like to have a DataGridView reflect a table from the database. Of course I could make my own routine manually setting the columns and fill the DataGridView, but if it is a way, I'd like to use the DataSource property or some other built-in function. I found a forum post that looked promising, but unfortunately I couldn't find the attachment that was referred to.
Also, if there are other controls better suited for this than the DataGridView, please let me know.
Thanks
DAO documentation isn't hard to find. Install VB6 and the Microsoft Developer Network (a disk was bundled with VB6). Go into the VB6 IDE, view your code, put the cursor on a DAO keyword, press F1. Presto - helpful documentation! If you prefer an online reference, the DAO documentation from Access 2007 should meet your needs very well.
So you want to bind a DataGridViewTable to a DAO table? Nice idea, but it's a big ask. Did the VB6 app use data-binding?
If it did, you're going to have a hard time migrating that to VB.Net. Consider shifting to ADO.Net in the VB.Net replacement.
If it didn't, you might be able to use DAO from VB.Net via COM and you might find that the DAO-related VB6 can be ported to DAO-related VB.Net without much effort. I don't know.
One option would be to use a method found in Code Complete. Put a nice, clean layer between the VB.NET user interface and the legacy data access code (your DAO code). The layer would take the data fetched via DAO and transfer it into a DataTable object. Then, you send the DataTable to the UI and use it as the .DataSource property of the DataGridView.
Honestly, however, since this involves writing code for each DAO function that returns data for you to display, I would just refactor your data access routines into ADO.NET. Since DAO is so, so, so old, in my opinion it would be irresponsible to be creating a "new" application and using such outdated technology, even though it technically can "work".

Switching Access 2007 accdb backend to SQL server express / Best frontend options?

After reading many posts on this site, I am considering replacing my accdb be (2007) with SQL Server or SQL Server Express? My fe is currently accdb (accde upon deployment). Is there any advantage to connecting to SQL using .adp as opposed to .accde? I currently link to tables in SQL using ocdb and it seams to work fine.
The only other question I have is, how much effort is it to create my fe forms using Visual Basic in Visual Studio Express? The idea of having a standalone exe makes it tempting. Am I looking at a big learning curve to go from vba to vb? I'm assuming the functionality of my code can be replicated in vb with some changes required.
Just seems like a good time to make this decision, while I'm still in the design stage.
It’s a big leap to go from a full access application to a .Net application with an SQL server backend. I have been going through this for 4 or 5 applications over the past year and what I did was to split the move into 2 parts.
First I migrated the data to SQL server but kept the access front end. I then look closely at the reasons why I would change the front end, for some of the applications it is just not worth the time to rewrite them when the only feature I would be gaining is an .exe extension and not a .mdb one!
Some however it was worth the time and so I have migrated them over but you have to look at what you are gaining, the Access front end / SQL server backend is a very powerful combination
I have worked with MS Access since version One and SQL Server since version 6.5. Access is indeed a relational database, and always has been. I've even seen Data Warehousing done in Access. My answer to RYK would be this: Access is an AWESOME front end for SQL Server for all the reasons that really matter. Access includes Forms, Queries, Reports, Macros and Code Design all in one package. Access has all of these features AND they are extensive. Form design is elegant. Report design is feature rich. Queries and Data Design does everything you want it to. VBA is fully functional. VB.NET/C# will work but .NET development takes longer than Access development. Access even lets you quickly test data scenarios and situations before the data is imported to SQL Server. If anyone knows of an application that has more features than Access all in one app please, please let me know what that is. Access even allows users to perform ad-hoc queries if they know how to. I should add that I am an ASP.NET VB.NET C# Developer and Crystal Reports Designer. I also design Oracle solutions. For over 10 years now if you Have MS Office and SQL Server you can do ANYTHING with data, and do it easier. (Excel Reports, Visio Data Modeling, Data Warehousing, Word Mail Merging, Full featured database apps, you name it) Visual Studio and .NET just add different flavors of icing to an already large and delicious cake.
May I suggest you download and give Visual Studio Lightswitch a go. Really fantastic for replacing/upgrading Access forms apps. You also would not need to worry about what connections to use etc. I find this tool really useful and friendly to replace/replicate access apps and spreadsheets the business was used to use.

Creating stored queries programmatically with vb.net, odbc and access

i have developed a small ms-access based software with vb.net.
I've added auto-update capabilities to the software (mostly by using clickonce) to simplify the release of new features.
Every version of the software executes the update routine which may update also the existing database.
Lately i've made few changes on the database structure adding few stored queries, so i want the autoupdate code to programmatically add these new queries to the existing database and make it perfectly up to date.
I haven't already found a solution to add stored queries to an ms-access database using odbc...
I also tried to use the "CREATE PROC" sql statement but it does not seem to work with access databases, even if i create the query form the Microsoft Office Access front-end.
I've found some examples that uses ADODB, but i'm using odbc to remain both x86 and x64 compliant.
PS: sorry for my bad english... I hope i've been clear enough
Stored queries in Jet/ACE are of two types, SELECT queries and what Access calls "Action" queries. SELECT queries correspond to VIEWS and action queries to SPROCs. So, if it's a DML statement, you'd create it as an SPROC, while if it's a SELECT, as a VIEW.
The one thing I'm not sure of is how parameters interact with this. I don't use Jet/ACE except from Access, so this is not something that I'm experienced with doing, so don't really have the answer for that.
If you can set a reference to DAO (which is actually much "closer to the metal" of Jet/ACE than ADO is), check the CreateQueryDef method and the QueryDefs collection.

JET SQL: do LEFT JOINS and RIGHT JOINS only work under JET 4.0 and above?

Does the following article apply to all uses of JET (including from within client apps via DAO or OLEDB):
http://support.microsoft.com/kb/275058
Does this mean JET 4.0 or above is mandatory for anything involving an Access MDB?
Unfortunately, the KB article is worded poorly. The SQL 92 syntax to which they refer is when you add a non-column comparison filter in the ON clause of an OUTER join (which also means it will not be viewable in the QBE). Thus, a standard outer join (LEFT or RIGHT) with standard column comparisons to tables in the query will work just fine in all versions of Jet. It is when you try to add something other than column comparison filter (e.g. [Col] > 200) in the ON clause of an OUTER join that Access does not properly interpret the SQL statement.
I have personally run into this very issue, In short, just because it is standard SQL does not mean that Access will return the proper results. It is one of the many things that many people find frustrating about Access.
ADDITION To answer your last question, no, it is not mandatory to use Jet as the backend storage technology for an application developed with Access. You can create Access solutions that use SQL Server or other database products as the backend database store.
The Wikipedia article on the Jet Engine is actually pretty thorough in describing the differences and features.
EDIT:
I just reread the KB article, and it says the problem is with Jet 4.0 Service Pack 3 and earlier -- that's a version of Jet that has long, long ago been superseded. There should be no Windows 2000 or later computers anywhere that have Windows Update turned on or that have been updated since c. 2002 that have any version of Jet as old as service pack 3. To check the version of Jet on your computer, find MSJET40.DLL. The build number begins with the service pack number. On this PC, I have version number 4.0.9511.0, so that's SP9.
If you have an MSJET40.DLL with version number 4.0.3XXX.X or earlier, then follow the instructions on getting the service pack, and the problem will be resolved. But I don't believe there's any signficant number of Windows PCs out there that still have Jet 4.0 SP3 or earlier on them. And only PCs that aren't being updated with Windows Update could possibly have it.
ORIGINAL ANSWER:
Jet 4.0 was released in 1999 with Access 2000. It was included in in Windows 2000 and is included in every version of Windows since. Because it's an OS component (it is used for interaction with the Active Directory data store, though AD uses the other Jet engine, not the one used by Access). Jet 4.0 is a frozen version of Jet and will not be developed any further by the Windows team (who owns the code for it).
When Access 2007 was released, a new version of the Jet database engine was created, private to the Access development team, and called ACE. It is really Jet 5.0 (or 4.5, depending on how major you consider the enhancements to be), but it introduced a new file format, ACCDB.
The article you cite says it applies to only Access 2002 and Access 2003, but I'd think that since it's a Jet 4.0 issue, it would also apply to Access 2000. Likewise, it would apply to any use of Jet 4.0 from outside Access, e.g., OLEDB or ODBC.
Note that via DAO, you can't encounter the problem, because DAO cannot use SQL 92 compatibility mode. The problem will always occur with OLEDB because the Jet driver for OLEDB always uses SQL 92 mode.
It's not clear to me if the problem is avoided if you use ACE to query an MDB.
JET is the database engine used by Access. Or put it another way, Access is an app built on the JET database engine. (Access doesn't have to use JET, it can also connect directly to SQL server.)
When ever you execute queries against an .mdb file, regardless of technology, it is the JET engine that executes the query.
A version of JET is needed to access a .mdb, but wether it has to be 4.0 will depend upon the .MDB file version and whether there are prevalent bugs in earlier versions that you need to avoid. But in general, yes, you should expect to use the latest JET version with an Access MDB.
OUTER JOINs work on older versions - the bug mentioned is only prevalent when there is also a WHERE clause.

Different approaches to accessing SSAS

I’m interested in knowing some different approaches for retrieving data from Analysis Services, to use in either objects in code, or for end-user reporting.
I’ve used two different approaches in the past, one was using ADOMD to pull results and put these into a dataset, the other was using SQL OPENQUERY to a linked SSAS server to get results out as a SQL stored procedure result set. Both of these had advantages and disadvantages.
Over the years I’ve seen various questions along this line, so forgive me for any duplication, but what other methods are there for getting SSAS data into a format where other people’s code could use it?
I’ve considered XML result sets from SSAS over HTTP, then Linq to XML – Anyone have any experience with that?
Ideally I’d like a dataset with typed columns, or objects with properties, but I’m more interested in general approach than code samples. How have you got data from SSAS, apart from SSRS/Other dashboard controls?
I know MS is supposed to support XML/A (XML for Analysis). I am shortly releasing an ajax library to do XML/A requests from web pages.
While I am currently focused on Pentaho's Mondrian, it should work for MS SQLs XML/A too. If you are interested, I am doing a presentation on it on January 13. (see: http://wiki.pentaho.com/display/COM/January+13,+2010+-+Roland+Bouman+-+OLAP+and+Analysis+for+web+applications+using+XMLA) I will be releasing my code by that time too (probably underr a LGPL license)
I would love to get feedback from people that use other XML/A servers, so if you are interestd, it would be great to work together on this.
UPDATE:
the project is now available at http://code.google.com/p/xmla4js/ There is API documentation, code samples, and build scripts. It's LGPL so you're free to use it in your applications, even for commercial purposes. The license does require that you release any modifications to the library itself as LGPL (but this does not affect the application that uses the library)
UPDATE2
The project no resides on github at https://github.com/rpbouman/xmla4js
It works in the browser as well as in nodejs.
I've never used it myself, as we only use ADOMD and Excel to connect to SSAS, but at some point we considered using HTTP and XML. We ended up going the ADOMD route because of a shortened dev schedule, but I guess it's another option that allows for access to SSAS outside of the .Net world.
Here's a link which I found useful when prototyping: Configuring HTTP Access to SQL Server 2008 Analysis Services on Microsoft Windows Server 2008
XMLA is the "high power" approach -- but I'm not aware of a toolkit or library that really exposes the full capabilities of XMLA; I think you would have craft it up yourself. For the projects I've done, that's just way too much work.
Instead, I used ADOMD.NET for retrieving results in code; the CellSet class in particular is fairly rich. For end user analysis (slice and dice), most often I use Excel Pivot Charts (which are fabulous!); sometimes I also use Visio Pivot Diagrams. For fixed reporting, Reporting Services can access SSAS directly, and it even has it's own query builder.
BTW, in case it helps, I have a chapter in my book about integrating SSAS with web sites as a way of offloading SQL Server: Ultra-Fast ASP.NET. My code examples use ADOMD; I also walk through building a simple cube, configuring automatic updates with SSIS, using proactive caching, building simple MDX queries, etc.
Another approach is to use the MSOLAP OLE DB provider. Our code is currently using this method.
Another way (and I would say the simplest one) to get data from SSAS OLAP cubes into .NET is by using LINQ + ADO.NET Entity Framework + SSAS Entity Framework Provider .
(I work for the company that developed SSAS Entity Framework Provider).