Migrating from obsolete DAO classes

早过忘川 提交于 2021-01-29 02:56:14

问题


I've got a C++ system developed in VS 2002/3 that I'm upgrading to current tech and it makes extensive use of CDAO classes (CDAODatabase, etc.). These are deprecated as of VS 2005 and unavailable in x64-compiled code.

I can't figure out what data access classes i should be migrating to for this upgrade. Any suggestions? Is there a particular set of classes that I can just drop in and get the same functionality with minimal code updates?


回答1:


Your options would be ODBC, OLE DB & ADO All of them offer access to multiple databases (using the respective provider), while DAO is basically for Microsoft Access (although I think supports an ODBC bridge).

ODBC is the most legacy but also the one with better support in the MFC Wizards (although also the worst performance). You can use the raw C API of ODBC or the MFC wrapper classes like CDatabase, etc (those MFC classes are also used by the MFC App Wizard that connects to ODBC). The MFC classes follow a similar object model than the ones for DAO (CDaoDatabase, etc).

OLE DB has best performance but is very low level (although there is also support for it in the MFC wizards). You can use it from the raw C COM API or with the smart pointers wrappers that the MFC App Wizard generates

Finally ADO, sits on top of OLE DB (so a provider that is OLE DB compatible is also usable with ADO). Not as good performance as OLE DB, but much more friendly. ADO was often the technology of choice in ASP (pre .NET), VB6, etc. You can use ADO in three ways:

  • Using the raw C COM API (low level, not recommended).

  • Using the MFC Class wizard (or equivalent in latest versions) that generates MFC wrapper classes around the COM interfaces.

  • Using the #import directive, that generates smart pointer wrappers (and uses several types that ease use like bstr_t, variant_t, etc) and C++ exception wrappers for the ADO errors.

I prefer the #import method with ADO, for samples, see

http://msdn.microsoft.com/en-us/library/windows/desktop/ms677563(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms677493(v=vs.85).aspx



来源:https://stackoverflow.com/questions/26718560/migrating-from-obsolete-dao-classes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!