“ODBC驱动程序不支持动态记录集”错误的解决

         

 在使用VC进行数据库编程时我遇到一个问题。代码编译通过,在运行时突然弹出一个警告对话框,如下图:

    

我纳闷在哪里出了问题。我想唯一有可能的是连接数据库时出现了问题。于是我找到连接数据库的代码:

m_pdatabase->Open(NULL,FALSE,FALSE,"ODBC;DSN=libraryMIS;UID=txm;PWD=txm");

其中m_pdatabase是一个CDatabase类的指针。于是我查msdn,找到CDatabaseOpen函数。CDatabase::Open

virtual BOOL Open( LPCTSTR lpszDSN, BOOL bExclusive = FALSE, BOOL bReadOnly = FALSE, LPCTSTR lpszConnect = “ODBC;”, BOOL bUseCursorLib = TRUE );
throw( CDBException, CMemoryException );

   我猜到问题可能出在哪儿了,我在BOOL bUseCursorLib设置了默认值TRUE。我得先看看bUseCursorLib表示什么意义。bUseCursorLib

 

TRUE if you want the ODBC Cursor Library DLL to be loaded. The cursor library masks some functionality of the underlying ODBC driver, effectively preventing the use of dynasets (if the driver supports them). The only cursors supported if the cursor library is loaded are static snapshots and forward-only cursors. The default value is TRUE. If you plan to create a recordset object directly from CRecordset without deriving from it, you should not load the cursor library.

  大意是说假如bUseCursorLibTRUE时,ODBC光标库将被加载。光标库会覆盖ODBC驱动程序的一些功能,有效地阻止动态记录集的使用(假如ODBC驱动程序支持动态记录集的使用的话)。假如光标库被加载唯一的光标支持的是静态快照集和唯一向前的光标。参数默认值是TRUE。假如你直接创建一个CRecordset类对象而不是继承自它,你不应该装载光标库。

   因此问题的解决办法是将bUseCursorLib的值设为FALSE。当我这样做了,问题解决了。

 

 

原文地址:https://www.cnblogs.com/lanzhi/p/6471315.html