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 8751557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:04:17+00:00 2026-06-13T13:04:17+00:00

I am writing a ODBC-database class which contains a member function used to fetch

  • 0

I am writing a ODBC-database class which contains a member function used to fetch a series of attributes and tuples from a given query.

I have a single line of code in the statements below which causes this runtime error to be throw in debug mode:

Unhandled exception at <mem loc> in <prog name>: 0xC0000005: Access violation writing location <mem loc>.

and here is the code where ERROR points out the offending line:

SQLINTEGER length = 0;
vector<vector<string>> data;
this->sReturn = SQLFetch(this->sHandle);

while (this->sReturn == SQL_SUCCESS) {
  vector<string> tuple;

for (int i = 0; i < columnCount; i++) {
  SQLPOINTER value = "";

  switch (info[i].columnType) {
    case 0 : //SQL_UNKNOWN_TYPE
      throw DatabaseAttributeTypeUnknown("The database returned an attribute of an unknown type.");
      break;

    case 1 : //SQL_CHAR
      this->sReturn = SQLGetData(this->sHandle, i + 1, info[i].columnType, value,
        info[i].columnSize*sizeof(SQLCHAR),
ERROR   &length);
        break;

     //Some more cases
  }
}

Any idea on why this error is being thrown? Here is the MSDN documentation on SQLGetData(), which is assigning a value to length.

Thank you for your time.

  • 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-13T13:04:18+00:00Added an answer on June 13, 2026 at 1:04 pm

    When a compiler maps executable code to line of code in the sources, they generally cannot differentiate lines in a statement that is split into multiple lines. So if the debugger says that an error happens on a specific line, it can actually be anywhere in the entire statement, so somewhere in:

    this->sReturn = SQLGetData(this->sHandle, i + 1, info[i].columnType, value,
        info[i].columnSize*sizeof(SQLCHAR),
        &length);
    

    The only shaky pointer here is value which point to a null static string, so to a one character long array containing a null byte. Also, depending on compiler options, this array can be in a read-only segment of data. While SQLGetData() thinks it points to a location which is at least info[i].columnSize*sizeof(SQLCHAR) bytes in size and where it will write (not read) the data from the SQL column.

    I may miss other details, but my first guess is that is what causes the memory access violation.

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

Sidebar

Related Questions

I am writing a small utility to copy a database from a proprietary ODBC
I've been writing a multi-threaded DLL for database access using ADO/ODBC for use with
I'm writing code, which can execute SQL queries via ODBC. For it I'm running
Writing an app which takes the preview frames from camera does some transformation to
Writing htaccess that allows me to remove index.php from the URL can confuse search
I have a project in which I'm accessing a MySql database on my web
Writing an iPhone app in which I want to save the user the grief
Writing a function to generate and push some random data inside of the unknown
I am writing a Windows application that will connect to a Sybase database through
I am getting the following ODBC exception when I moved my development platform from

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.