http://support.microsoft.com/default.aspx?scid=kb;en-us;901259

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:

[….]

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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here