【问题标题】:Access violation reading location when using mongocxx driver使用mongocxx驱动时访问冲突读取位置
【发布时间】:2019-03-07 15:52:24
【问题描述】:

我在使用 mongodb c++ 驱动程序时遇到了一些问题。

我有以下代码,它运行良好:

//bsoncxx::document::value doc-->It was defined properly before

static mongocxx::instance inst{};

mongocxx::client conn{ mongocxx::uri{} };

auto db = conn["Test"];

auto res = db["Executions"].insert_one(std::move(doc));

但是当我改为:

static mongocxx::instance inst{};

mongocxx::client conn{ mongocxx::uri{} };

auto db = conn[dbName];

auto res = db[colName].insert_one(std::move(doc));

(dbName 和 colName 是函数的字符串参数)

当代码到达该行时:

auto db = conn[dbName];

我得到以下异常:

Access violation reading location 0x0000726F74636570

我使用的是 Windows 7 x64 和 Visual Studio 2017

有人知道为什么会这样吗?

感谢您的宝贵时间。

【问题讨论】:

    标签: c++ mongodb visual-studio windows-7-x64 mongo-cxx-driver


    【解决方案1】:

    这里没有足够的信息可以确定,我会大胆猜测并说你正在混合调试和发布运行时,这样std::string 在内部结构之间有不同的布局编译后的mongocxx 库和您的应用程序。

    为您希望能够使用的每种形式的 CRT 构建一次驱动程序非常重要,并且您的应用程序根据其当前构建配置选择正确的驱动程序。

    https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=vs-2017

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      相关资源
      最近更新 更多