Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I suppress warning c4996 caused due to using deprecated methods of ODBC API

Full warning message is:

warning C4996: 'SQLSetConnectOption': ODBC API: SQLSetConnectOption is deprecated. Please use SQLSetConnectAttr instead.

like image 605
MykelXIII Avatar asked Nov 28 '25 06:11

MykelXIII


1 Answers

The quick answer is to use #pragma warning(disable: 4996) around the call to SQLConnectOption:

#pragma warning(push)
#pragma warning(disable: 4996)

rc = SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);

#pragma warning(pop)

A more involved approach is to replace your calls to SQLSetConnectOption with equivalent calls to SQLSetConnectAttr.

There is a fairly detailed msdn article here (MSDN Article on SQLSetConnectOption Mapping) that explains how to convert the function call. In most cases it appears fairly trivial; the first three arguments are identical, and the new 4th argument (StringLength) is either SQL_NTS if the value parameter is a string, 0 if it is an integer, or a length value if it is a driver-defined paramter.

like image 77
giles Avatar answered Nov 29 '25 18:11

giles



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!