0

I am trying to connect the SOCI library to my database but keep on receiving this error on my VS compiler output.

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:

enter image description here

Can someone please guide me about what I am doing wrong?

Trinidad
  • 2,756
  • 2
  • 25
  • 43
Erdos_x
  • 3
  • 1
  • I have also looked into that what we need for SQLDriverConnect but can't seem to understand. Can someone give me an example? – Erdos_x Apr 05 '17 at 14:47
  • Search Stack Overflow on how to set the compiler switch _CRT_SECURE_NO_WARNINGS. THere are plenty of questions and answers on this. – acraig5075 Apr 05 '17 at 14:47
  • I have added that to the preprocessor. My problem is that I am not too sure what parameters I need to set to connect to my ODBC ms_sql. The website guide is the following [link](http://soci.sourceforge.net/doc/3.2/backends/odbc.html). Can you help me with this guide? I do apologize as it seems simple but I can't seem to follow. – Erdos_x Apr 06 '17 at 10:06

1 Answers1

0

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. See here for more


To connect to ODBC you can use a connection_parameters object to pass the connection details as follows:

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

Sampath
  • 1,144
  • 1
  • 21
  • 38