简体   繁体   English

SOCI ODBC连接错误

[英]SOCI ODBC Connection ERROR

I am trying to connect the SOCI library to my database but keep on receiving this error on my VS compiler output. 我正在尝试将SOCI库连接到我的数据库,但在VS编译器输出上继续收到此错误。

My code is : 我的代码是:

{
  try
  { 
    backend_factory const& backEnd = odbc;
    std::string const & connectString = "DSN=CVD_SQL_connection_2016b_64bit";
    session sql(backEnd, connectString);

  }
  catch (const std::exception& e)
  {

    cerr << e.what();
  }

  return 0;
}

The error warnings are the following: 错误警告如下:

在此处输入图片说明

Can someone please guide me about what I am doing wrong? 有人可以指导我做错什么吗?

You can use 您可以使用

#define _CRT_SECURE_NO_WARNINGS

or 要么

#pragma warning(disable : 4996)

to suppress the warning. 禁止警告。

Or use: 或使用:

#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1

to let the compiler automatically replace strcpy() with strcpy_s() for you. 让编译器为您自动将strcpy()替换为strcpy_s() See here for more 看到这里更多


To connect to ODBC you can use a connection_parameters object to pass the connection details as follows: 要连接到ODBC,可以使用connection_parameters对象传递连接详细信息,如下所示:

connection_parameters parameters("odbc", "DSN=CVD_SQL_connection_2016b_64bit");
parameters.set_option(odbc_option_driver_complete, "0");
session sql(parameters);

Don't forget to include the soci-odbc.h 别忘了包含soci-odbc.h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM