CRecordset::snapshot 在 VS2012 中不再工作 - 有什么替代方案?

2022-01-12 00:00:00 winapi odbc c++ mfc

显然,在 VS2012 中,不推荐使用 SQL_CUR_USE_ODBC.[更新:游标库似乎已从 VS2012 中完全删除].

Apparently, in VS2012, SQL_CUR_USE_ODBC is deprecated. [Update: it appears that the cursors library has been removed from VS2012 entirely].

MFC 的 CDatabase 不再使用它(而它是 VS2010 和更早版本 MFC 的默认设置),而是使用 SQL_CUR_USE_DRIVER.

MFC's CDatabase doesn't use it anymore (whereas it was the default for VS2010 and earlier versions of MFC), but instead uses SQL_CUR_USE_DRIVER.

很遗憾,SQL_CUR_USE_DRIVER 不能与 Jet ODBC 驱动程序一起正常工作(我们正在与 Access 数据库交互).驱动程序最初声称支持位置操作(但不支持位置更新),但是当尝试实际查询数据库时,所有并发模型都会失败,直到 MFC 库下降到与数据库的只读交互(这不会为我们飞).

Unfortunately, SQL_CUR_USE_DRIVER doesn't work properly with the Jet ODBC driver (we're interacting with an Access database). The driver initially claims to support positional operations (but not positional updates), but when an attempt is made to actually query the database, all concurrency models fail until the MFC library drops down to read-only interaction with the database (which is not going to fly for us).

问题

  • 这是 MS 强制开发人员放弃基于 Jet 的数据源并迁移到 SQL Express(或类似)的最新尝试吗?
  • 我们应该使用另一种方式通过 VS 2012 版本的 MFC/ODBC 与 Access 数据库进行交互吗?(1)

另请参阅:http://social.msdn.microsoft.com/Forums/kk/vcmfcatl/thread/acd84294-c2b5-4016-b4d9-8953f337f30c

更新:查看各种选项,似乎游标库已从 VS2012 的 ODBC 库中删除.结合 Jet 不能正确支持位置更新 (2) 的事实,它使快照"模式无法使用.只要基础表具有主键,它似乎就支持动态集".无键表与动态集"模式 (3) 不兼容.所以 - 我可以坚持使用 VS 2010,或者我可以更改我的表格以包含自动编号或类似的东西,以确保 pkey 可用,以便我可以对记录集使用动态集模式.

Update: Looking at the various options, it seems that the cursor library has been removed from VS2012's ODBC library. Combined with the fact that Jet doesn't correctly support positional updates(2), it makes "snapshot" mode unusable. It does appear to support "dynaset" as long as the underlying tables have a primary key. Unkeyed tables are incompatible with "dynaset" mode(3). So - I can stick with VS 2010, or I can change my tables to include an autonumber or something similar in order to ensure a pkey is available so I can use dynaset mode for the recordsets.

(1) 例如我们应该为 CRecordset 使用不同的开放类型吗?我们目前使用 CRecordset::snapshot.但我从来没有真正理解快照、动态、动态集的各种模式.一组快速的尝试每个"未能为我们的访问数据库提供一个可工作的可更新界面...
(2) 它在最初查询时声称,但随后返回它之前声称支持的所有并发模式的错误
(3)动态"也出来了,因为 Jet 根本不支持它(从我的测试中可以看出).

(1) e.g. should we be using a different open type for CRecordset? We currently use CRecordset::snapshot. But I've never really understood the various modes snapshot, dynamic, dynaset. A quick set of "try each" has failed to get a working updatable interface to our access database...
(2) it claims to when queried initially, but then returns errors for all concurrency modes that it previously claimed to support
(3) "dynamic" is also out, since Jet doesn't support it at all (from what I can tell from my tests).

推荐答案

如果其他人遇到这个问题,这似乎是答案:

If anyone else runs into this issue, here's what seems to be the answer:

对于 ODBC 到 Access 数据库,使用 CDatabase mydb 连接;mydb.OpenEx(.., 0),这样就要求系统不要加载游标库.

For ODBC to an Access database, connect using CDatabase mydb; mydb.OpenEx(.., 0), so that you ask the system not to load the cursor library.

然后对于记录集,使用 dynaset CMyRecordset myrs;myrs.Open(CRecordset::dynaset, ...).

Then for the recordsets, use dynaset CMyRecordset myrs; myrs.Open(CRecordset::dynaset, ...).

最后,你必须确保你的表有一个主键才能使用动态集(keysets).

Finally, you must make sure that your tables have a primary key in order to use dynasets (keysets).

相关文章