Microsoft Knowledge Base Email Alertz

You receive an access violation error message when you call the Dispose method or the Close method to close an SPSite object or an SPWeb object in SharePoint Portal Server 2003 and in Windows SharePoint Services

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: 901259 - Last Review: January 30, 2007 - Revision: 2.4

You receive an access violation error message when you call the Dispose method or the Close method to close an SPSite object or an SPWeb object in SharePoint Portal Server 2003 and in Windows SharePoint Services

SYMPTOMS

Consider the following scenario in Microsoft Office SharePoint Portal Server 2003 and in Microsoft Windows SharePoint Services. You want to close an SPSite object or an SPWeb object. To do this, you call the Dispose method or the Close method of the SPWeb class or of the SPSite class. When you call the Dispose method or the Close method, the server unexpectedly crashes. Additionally, you receive an access violation error message that is similar to the following:
[COMException (0x80020009): Exception occurred.] Microsoft.SharePoint.Library.SPRequestInternalClass.UpdateWebPartCache(String bstrWebUrl, Boolean bAllUsers, String bstrID, Byte[]& ppsaData, Boolean fOMCall) +0 Microsoft.SharePoint.Library.a.a(String A_0, Boolean A_1, String A_2, Byte[]& A_3, Boolean A_4) [SPException: Exception occurred.] Microsoft.SharePoint.Library.a.a(String A_0, Boolean A_1, String A_2, Byte[]& A_3, Boolean A_4) Microsoft.SharePoint.SPWebPartCollection.a(Guid A_0, Byte[] A_1, Storage A_2, Boolean A_3) Microsoft.SharePoint.SPWebPartCollection.b(Guid A_0, Byte[] A_1, Storage A_2) Microsoft.SharePoint.WebPartPages.WebPart.OnUnload(EventArgs e) System.Web.UI.Control.UnloadRecursive(Boolean dispose) +121 System.Web.UI.Control.UnloadRecursive(Boolean dispose) +74 System.Web.UI.Control.UnloadRecursive(Boolean dispose) +74 System.Web.UI.Control.UnloadRecursive(Boolean dispose) +74 System.Web.UI.Page.ProcessRequestCleanup() +24 System.Web.UI.Page.ProcessRequest() +215 System.Web.UI.Page.ProcessRequest(HttpContext context) +18 Microsoft.SharePoint.ApplicationRuntime.SharePointHandler.SPProcessRequest(HttpContext context) [ApplicationException: Exception of type System.ApplicationException was thrown.] Microsoft.SharePoint.ApplicationRuntime.SharePointHandler.SPProcessRequest(HttpContext context) Microsoft.SharePoint.ApplicationRuntime.SharePointHandler.SPProcessRequest(HttpContext context) Microsoft.SharePoint.ApplicationRuntime.SharePointHandler.ProcessRequest(HttpContext context) System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +179 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87

CAUSE

This issue occurs if the SPWeb object or the SPSite object is a shared resource. For example, this issue occurs if the SPWeb object or the SPSite object is provided by the GetContext method in a Web Part. In scenarios where the SPWeb object or the SPSite object is provided by the GetContext method, you should not call the Dispose method or the Close method. The following sample code is an example of what not to do.
// Example of what not to do
//using (SPSite site = SPControl.GetContextSite (this.Context)) {
  // Code to perform a task
//}
 
// If you have to use a GetContext* method, let SharePoint dispose of 
// the object.  The object is a shared resource.
SPSite site = SPControl.GetContextSite (this.Context);
  // Code to perform a task
// site.Dispose ();  <-- Do not call the Dispose method or the Close method on a shared resource. Leave this line commented.

RESOLUTION

If you create your own SPWeb object or SPSite object, you can use the Dispose method or the Close method to close the object. However, if you have a reference to a shared resource, do not use the Dispose method or the Close method to close the object. In scenarios where you have a reference to a shared resource, such as when the objects are provided by the GetContext method, let SharePoint Portal Server 2003 and Windows SharePoint Services manage the object.

MORE INFORMATION

For more information about the Dispose method and Close method of the SPWeb class, visit the following Microsoft Web site:
http://msdn2.microsoft.com/en-us/library/ms978653.aspx (http://msdn2.microsoft.com/en-us/library/ms978653.aspx)
For more information about the Dispose method and Close method of the SPSite class, visit the following Microsoft Web site:
http://msdn2.microsoft.com/en-us/library/ms978559.aspx (http://msdn2.microsoft.com/en-us/library/ms978559.aspx)
For more information about the SharePoint Portal Server object model and the Windows SharePoint Services object model, see the Microsoft SharePoint Products and Technologies 2003 Software Development Kit (SDK). To view the SharePoint Products and Technologies 2003 SDK, visit the following Microsoft Web site:
http://msdn2.microsoft.com/en-us/library/ms954103.aspx (http://msdn2.microsoft.com/en-us/library/ms954103.aspx)

APPLIES TO
  • Microsoft Office SharePoint Portal Server 2003
  • Microsoft Windows SharePoint Services 2.0
Keywords: 
kberrmsg kbtshoot KB901259
       

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