Microsoft Knowledge Base Email Alertz

(217187) - Access violation can occur when using OLE DB Provider Template macro with SCHEMA_ENTRY.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 217187 - Last Review: August 28, 2003 - Revision: 1.3

FIX: Failure In InternalCreateSchemaRowset Causes Access Violation

This article was previously published under Q217187

SYMPTOMS

Access violation can occur when using OLE DB Provider Template macro with SCHEMA_ENTRY.

CAUSE

Following is the code in ATLDB.H for CreateSchemaRowset. CreateSchemaRowset is called by the SCHEMA_ENTRY macro.

The rowset class is created and then a pointer to it is sent to InternalCreateSchemaRowset.

NOTE: A failed hr will cause the object to be deleted.

HRESULT CreateSchemaRowset(IUnknown *pUnkOuter, ULONG cRestrictions,
			   const VARIANT rgRestrictions[], REFIID riid,
			   ULONG cPropertySets, DBPROPSET rgPropertySets[],
			   IUnknown** ppRowset, SchemaRowsetClass*& pSchemaRowset)
{
  HRESULT hrProps, hr = S_OK;
  SessionClass* pT = (SessionClass*) this;
  CComPolyObject<SchemaRowsetClass>* pPolyObj;
  if (FAILED(hr = ComPolyObject<SchemaRowsetClass>::CreateInstance(pUnkOuter, &pPolyObj)))
    return hr;
  
  pSchemaRowset = &(pPolyObj->m_contained);
  hr = InternalCreateSchemaRowset(pUnkOuter, cRestrictions, rgRestrictions,
riid, cPropertySets, rgPropertySets, ppRowset,pPolyObj, pT, pT->GetUnknown());

  // Ref the created COM object and Auto release it on failure
  if (FAILED(hr))
  {
//Here is the problem delete
    delete pPolyObj; // must hand delete as it is not ref'd
    return hr;  
  }
}
				


Following is the code for InternalCreateSchemaRowset. If a failure occurs when trying to set a property, the function returns with an error but not before the spUnk smart pointer calls release and frees the object. When execution returns from this function, the CreateSchemaRowset function attempts to delete the object (which has already been deleted) and the access violation occurs.

OUT_OF_LINE HRESULT InternalCreateSchemaRowset(IUnknown *pUnkOuter, ULONG cRestrictions, const VARIANT rgRestrictions[], REFIID riid,						   ULONG cPropertySets, DBPROPSET rgPropertySets[], IUnknown** ppRowset, IUnknown* pUnkThis, CUtlPropsBase* pProps, IUnknown* pUnkSession)
{
  HRESULT hr, hrProps = S_OK;
  if (ppRowset != NULL)
    *ppRowset = NULL;
  if ((pUnkOuter != NULL) && !InlineIsEqualUnknown(riid))
    return DB_E_NOAGGREGATION;

//Smart pointer, spUnk will automatically call Release() when it goes out of scope
  CComPtr<IUnknown> spUnk;
  hr = pUnkThis->QueryInterface(IID_IUnknown, (void**)&spUnk);
	
  if (FAILED(hr))
    return hr;
  hr = pProps->FInit();
  if (FAILED(hr))
    return hr;
  hr = pProps->SetPropertiesArgChk(cPropertySets, rgPropertySets);
  if (FAILED(hr))
    return hr;
  const GUID* ppGuid[1];
  ppGuid[0] = &DBPROPSET_ROWSET;

  // Call SetProperties.  The true in the last parameter indicates
  // the special behavior that takes place on rowset creation (i.e.
  // it succeeds as long as any of the properties were not marked
  // as DBPROPS_REQUIRED.

  hrProps = pProps->SetProperties(0, cPropertySets,rgPropertySets,1,ppGuid, true);
  if (FAILED(hrProps))
    return hrProps;
}
				

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug was corrected in Visual Studio 6.0 Service Pack 3. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why  (http://kbalertz.com/Feedback.aspx?kbNumber=194022/EN-US/ )

194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed  (http://kbalertz.com/Feedback.aspx?kbNumber=194295/EN-US/ )

APPLIES TO
  • Microsoft OLE DB 2.7, when used with:
    • Microsoft Visual C++ 6.0 Enterprise Edition
    • Microsoft Visual C++ 6.0 Professional Edition
    • Microsoft Visual C++, 32-bit Learning Edition 6.0
Keywords: 
kbbug kbdatabase kbdtl kbfix kbmdacnosweep kbprovider kbvs600sp3fix KB217187
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate