BUG: ADO Recordset GetString() Function Throws an Access Violation in Oleaut32.dll

ID: Q230276


The information in this article applies to:


SYMPTOMS

Calling the GetString() function on a _RecordsetPtr object may cause the following error to occur:

Unhandled Exception in <application name> (OLEAUT32.DLL) : 0xC0000005: Access Violation


CAUSE

The #import-generated wrapper function GetString() passes an uninitialized BSTR pointer to the ADO raw_GetString() function as an out parameter. The raw_GetString() function incorrectly calls the SysFreeString() function on the parameter if it is not pointing to NULL.


RESOLUTION

Call the raw_GetString directly and pass a BSTR pointer that points to NULL as the output parameter, or create a wrapper function as described in the More Information section.


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

Steps to Reproduce Behavior

These steps use the SQL Server Pubs database:
  1. Create a Win32 console application (Simple application) in Visual C++.


  2. Paste the following code to replace code generated in the .cpp file:
    
    #include "stdafx.h"
    #include <iostream.h>
    
    #import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename( "EOF", "adoEOF" )
    
    struct InitOle {
      InitOle()  { ::CoInitialize(NULL); }
      ~InitOle() { ::CoUninitialize();   }
    } _init_InitOle_;
    
    int main(int argc, char* argv[])
    {
    
    	try {
    		_ConnectionPtr pCon(__uuidof(Connection));
    		_RecordsetPtr pRs(__uuidof(Recordset));
    
    		pCon->ConnectionString = L"Provider=SQLOLEDB.1; Server=(local);Initial Catalog=pubs; User Id=sa; Password=;";
    		pCon->Open(L"",L"",L"",-1);
    
    		pRs->Open(L"SELECT * FROM authors",pCon.GetInterfacePtr(),adOpenStatic,adLockOptimistic,-1);
    
    		_bstr_t btRecordset;
    		btRecordset = pRs->GetString(adClipString,-1,L",",L"\r\n",L"<NULL>");
    		cout << (char*) btRecordset << endl;
    	}
    	catch (_com_error& e)
    	{
    		cout << e.ErrorMessage() << endl;
    	}
    
    	return 0;
    }
     


  3. Run the code and observe the results.


Resolution

Additional query words: mdac


Keywords          : kbADO kbDatabase kbMDAC kbGrpVCDB kbGrpMDAC 
Version           : WINDOWS:2.0,2.1,6.0
Platform          : WINDOWS 
Issue type        : kbbug 

Last Reviewed: May 7, 1999