title: C++ ODBC Unhandled exception / Access violation writing location
body: <p>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.</p>
  
  <p>I have a single line of code in the statements below which causes this runtime error to be throw in debug mode:</p>
  
  <pre><code>Unhandled exception at &lt;mem loc&gt; in &lt;prog name&gt;: 0xC0000005: Access violation writing location &lt;mem loc&gt;.
  </code></pre>
  
  <p>and here is the code where <code>ERROR</code> points out the offending line:</p>
  
  <pre><code>SQLINTEGER length = 0;
  vector&lt;vector&lt;string&gt;&gt; data;
  this-&gt;sReturn = SQLFetch(this-&gt;sHandle);
  
  while (this-&gt;sReturn == SQL_SUCCESS) {
    vector&lt;string&gt; tuple;
  
  for (int i = 0; i &lt; 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-&gt;sReturn = SQLGetData(this-&gt;sHandle, i + 1, info[i].columnType, value,
          info[i].columnSize*sizeof(SQLCHAR),
  ERROR   &amp;length);
          break;
  
       //Some more cases
    }
  }
  </code></pre>
  
  <p>Any idea on why this error is being thrown? Here is the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms715441%28v=vs.85%29.aspx" rel="nofollow">MSDN documentation on SQLGetData()</a>, which is assigning a value to <code>length</code>.</p>
  
  <p>Thank you for your time.</p>