Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8987959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:54:53+00:00 2026-06-15T21:54:53+00:00

Recently, I’ve been trying to make a little test program to communicate with a

  • 0

Recently, I’ve been trying to make a little test program to communicate with a MySQL server in C++. I’m currently using MySQL Connector/C++ as my API to connect to my database server. It took me a very long time to get it running, because oracle/mysql has little to no documentation of how to use connector/c++ with Visual Studio 10+.

Finally after getting everything working, there seems to be some issue when the application tries to exit. It throws the following unhandled exception:

Unhandled exception at 0x00C62291 in mysql2.exe: Stack cookie instrumentation code detected a stack-based buffer overrun.

After researching about the error, I figured out it was due to the “security check” option (/gs compiler option). When I disable this compiler option, the application exits gracefully.

I have a feeling that I should not turn it off, as it is the default option in Visual Studio 2012 (and possibly other versions?)

My questions are:

  • Why is this /gs compiler option causing the unhandled exception?
  • Is it safe or okay to turn off the /gs compiler option?

Here is the piece of code the unhandled exception points to (inside a file, called: gs_report.c):

#if defined (_M_IX86) || defined (_M_X64)
    if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE))
#endif  /* defined (_M_IX86) || defined (_M_X64) */
    __fastfail(FAST_FAIL_STACK_COOKIE_CHECK_FAILURE);

Here is my application code:

/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>

/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#include "mysql_connection.h"
#include "mysql_driver.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

using namespace std;

int main(void)
{
    cout << endl;
    cout << "Let's have MySQL count from 10 to 1..." << endl;

    try {
        sql::Driver *driver;
        sql::Connection *con;
        sql::Statement *stmt;
        sql::ResultSet *res;
        sql::PreparedStatement *pstmt;

        /* Create a connection */
        driver = sql::mysql::get_driver_instance();
        con = driver->connect("tcp://127.0.0.1:3306", "root", "MSxa5y");
        /* Connect to the MySQL test database */
        con->setSchema("test");

        stmt = con->createStatement();
        stmt->execute("DROP TABLE IF EXISTS test");
        stmt->execute("CREATE TABLE test(id INT)");
        delete stmt;

        /* '?' is the supported placeholder syntax */
        pstmt = con->prepareStatement("INSERT INTO test(id) VALUES (?)");
        for (int i = 1; i <= 10; i++) {
            pstmt->setInt(1, i);
            pstmt->executeUpdate();
        }
        delete pstmt;

        /* Select in ascending order */
        pstmt = con->prepareStatement("SELECT id FROM test ORDER BY id ASC");
        res = pstmt->executeQuery();

        /* Fetch in reverse = descending order! */
        res->afterLast();
        while (res->previous())
            cout << "\t... MySQL counts: " << res->getInt("id") << endl;
        delete res;

        delete pstmt;
        delete con;

    } catch (sql::SQLException &e) {
        cout << "# ERR: SQLException in " << __FILE__;
        cout << "() on line " << __LINE__ << endl;
        cout << "# ERR: " << e.what();
        cout << " (MySQL error code: " << e.getErrorCode();
        cout << ", SQLState: " << e.getSQLState() << " )" << endl;
    }

    cout << endl;

    return EXIT_SUCCESS;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:54:54+00:00Added an answer on June 15, 2026 at 9:54 pm

    The /gs option is allowing the runtime to detect an error in your program. Removing the option allows the program to exit without detecting it, but the error is still there. Somewhere in your code or the libraries, memory on the stack is being overwritten. I’d try a binary search on the code to see which statement is leading to the error. You may also want to always check the return value from all of your database calls.

    You definitely should not disable this option. Doing so will hide real errors and may leave your program open to hacking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I am making a server-client program using multithread concept. For some reason, I
Recently I have been working with a SQL Server database and I was trying
Recently I had a problem using (pipe |-) when I wanted to communicate between
Recently I have been dealing with windows LogonUser API. The LogonUser api returns different
Recently I've attempted to make a simple program that would require moving a button
Recently the PHP manual started showing the following warning on every mysql function page:
Recently I've created one android application using eclipse and ran it using android virtual
Recently I have done an assignment, on overloading basic functionalists(+,-,conjugate...) of complex class using
Recently our WPF/Entity Framework 4.0 application has become unstable after we began using backgroundworkers
Recently I faced a issue when using len() in a query to find out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.