.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

IDisposable SPSite and SPWeb fixes

Posted By:      Posted Date: October 16, 2010    Points: 0   Category :SharePoint

I think those of you who know how to fix this will see the title and laugh....saying oh yea..I remember when I first discovered that.  So here we go.

MOSS2007.  Performance started going bad this week.  Very bad.  MS called in for support.  They ran a scan and pointed us to the stuff that we should address.  They pointed me at this MSDN Article basing on Stefan Goßner's writeup on fixing this stuff.  They asked me to run the SPDispose Utility against all of my custom code.  I did and the output showed no errors.

However, I scanned the log files of my DEV box, where I'm the only user.  I started some of my VS2008 Workflows.  I get the usual error

ERROR: request not found in the TrackedRequests. We might be creating and closing webs on different threads. ThreadId = 12, Free call stack =    at Microsoft.SharePoint.SPRequestManager.Release(SPRequest request)     at Microsoft.SharePoint.SPWeb.Invalidate()     at Microsoft.SharePoint.SPWeb.Close()     at Microsoft.SharePoint.SPSite.Close()     at Microsoft.SharePoint.SPSite.Dispose()     at RS_SDLC_Approv

View Complete Post

More Related Resource Links

Login to SPSite\SPWeb through console app using user/password

Hi,I'm developing some basic console application which interacts with SharePoint site through the object mode. I'm using:SPSite site = new SPSite(MySiteUrl); SPWeb web = site.OpenWeb(); This way, current windows user is acessing the site. Is it possible to supply the user with username/password to be able to acess with different credentials than current?Thanks in advance!

First Development Program with SPSite, SPWeb and SPList works only locally but not in farm

Dear All, Here is a piece of code which wrote in a VS 2010 with Standlone Sharepoint 2010 in Windows 7 64 bit and it works fine. Private Shared _SiteURL As String     Private Shared Sub Initialize(ByVal SiteURL As String)                 _SiteURL = SiteURL         Using sc As New SPSite(_SiteURL)             Dim spWebSite As SPWeb = sc.RootWeb             _AllSPList = New List(Of String)             _HiddenSPList = New List(Of String)             _VisibleSPList = New List(Of String)             For Each item As SPList In spWebSite.Lists                 _AllSPList.Add(item.Title)                 If item.Hidden = True Then                     _HiddenSPList.Add(item.Title)             &nb

disposing SPSite and SPWeb objects?

hi          can i code using(SPSite oSite=SPContext.Current.Site) {    using(SPWeb oWeb=oSite.OpenWeb()) {} } or should i code like this SPSite oSite=SPContext.Current.Site; using(SPWeb oWeb=oSite.Openweb()){} which is better? i am trying to code this inside ItemAdding Event handler. please suggest

179 heaps created, above warning threshold of 32. Check for excessive SPWeb or SPSite usage.

Hi All, I am gettings hundreds of following error messages in my sharepoint log files 179 heaps created, above warning threshold of 32. Check for excessive SPWeb or SPSite usage. Also I have noticed that after these error messages my sharepoint site is now dead slow. Any idea how to resolve this problem ?  

Error opening site using SPSite and SPWeb instances using VS 2010, Win Server 2008 R2


Hi I am trying to open my site using SPSite and SPWeb instances and getting an error message as below-

The Web application at http://url could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

  CODE is -



                    SPSite siteCOll = new SPSite(siteURL);

                    SPWeb oWeb = siteCOll.OpenWeb("url");



I can access site using browser perfectly.

I am running VS as administrator.

I have done permission checking aswell.


please help!





Error occured when using SPWeb or SPSite in webpart


I am creating a custom webpart, in which I have a label control. This label will display the current site URL and here is the code

protected override void CreateChildControls()
            SPWeb wb = SPContext.Current.Web;
            string baseURL = wb.Url.ToString();
            Label lblTitle = new Label();
            lblTitle.Text = baseURL.ToString();

But when I try to use SPWeb or SPSite within CreateChildControl method, I am getting an unexpected error occurred message. Also I have used "using Microsoft.SharePoint;" too.

If suppose I comment those two line my web part is displaying the properly. As below

protected override void CreateChildControls()
            //SPWeb wb = SPContext.Current.W

CLR Inside Out: Digging into IDisposable


This month: cleaning up resources that are not garbage collected by the CLR garbage collector.

Shawn Farkas

MSDN Magazine July 2007

Error connecting using SPSite

Has anyone seen this error message?

The Web application at http://ecnet/Pages/Default.aspx could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

Errors on the line.

SPSite site = new SPSite("http://ecnet/Pages/Default.aspx");

It's a clean console application running on the SharePoint 2007 web server.

Any thoughts? I can't seem to connect to the Server like I used to in SharePoint 2003.



hi all,

I'm trying to imitate what Sharepoint does when a user clicks on a file name and gets a dialog box for a read only access to the file. I have binged and googled and yahooed and asked and some others I forgot looking for ways of doing it in code using the sharePoint object model to no avail.

Can somebody share a little bit of knowledge on how I might start doing this or where to look for the informations.

What I'm trying to do is to bring the checking/checkout functionality to a gridview. I got the check-in/out ok but I have not been able to accomplish the file view in read only mode. using the postback url I can see the file but it comes as read/write and once I select the file then the link controls I'm using on the grid are deactivated and can't find out why.

this is the code I use to view the file..
control.PostBackUrl = string.Format("{0}{1}", urlHdr, row.Field<string>("FileLeafRef")); // this does not work!


Trying to get SPSite when called through a web service


I have built a custom timer job that makes calls to a web service that I built.  The reason I built the web service is because I recognized that the sharepoint timer job does not have context for a site and I thought that by having the timer job call the web methods of the web service I could have the context that I desire.  This works great for accessing the web.config file, however, I have discovered that I am unable to get SPSite (SPSite oSite = new SPSite(AbsoluteURL)).  The constructor does not throw an error but I am unable to use the new object.  If I am able to get to the web.config and the site is a SharePoint site I figure I should be able to get an SPSite object.

I am trying to understand if I am running into a known scenario or if this should work and that I have a bug that I don't recognize.

File not found for SPSite object

Hi,  I created a webapplication to access spsite object,When i try to access the site,I getting file not fount exception.If use the same code in windows form i am able to access the spsite object.Can any one tell me why its not working in web applications.I am using VS2008 and Moss 2007 is on the same machine. Thanks, Sreemouni.

Where to find the latest list of critical SQL Server fixes?

Hi, Where can I find the latest list of critical SQL Server fixes?

Can not init SPSite for claims based authenticated site

Hi, trying to write a simple console application i was not able to init a claims based authenticated site with API nor with the Managed Client OM. Opening a site with only windows authentication is working. Running on a Windows Server 2008 R2 and SP 2010 server and logged in as the buildin Administrator account. Administrator is Site Collection Admin. static void Main(string[] args) {     ClientContext context = new ClientContext("http://mypc:300");     Web web = context.Web;     context.Load(web);     context.ExecuteQuery();     ... } throws "The remote server returned an error: (403) Forbidden.". Setting credentials for the context is also not working. or same problem with     static void Main(string[] args) {     using (SPSite spSite = new SPSite("http://mypc:300"))     {         ... throwing FileNotFound-Error. Any idea? Greetings Peter  

Best way to query SPWeb propertybag

I have thousands of subsites that have all their data stored in propertybags in SharePoint 2010.  I need to query the SPWeb propertybag at the top site level for summations and some custom webparts.  I was wondering what was the best way to do this?  I not sure if the new LINQ To SQL will help with this or what the best solution would be.  Right now I'm just looping through all the subsites but their has to be a better way...  Any help is much appreciated!

SPWeb.Properties is not persist over the redirect page.

Hi, I have to pass some object from my code to another redirected page. So I serialize the object and serialized string is save to SPWeb's property as a string and after that I use SPUtility.Redirect('Url'). But on redirected page above updated property is not find in the SPWeb.Property collection. string xml = MyClass.GetXMLFromObject(exInfo); SPContext.Current.Web.Site.RootWeb.AllowUnsafeUpdates = true; SPContext.Current.Web.Site.RootWeb.Update(); if (!SPContext.Current.Web.Site.RootWeb.Properties.ContainsKey("MyInfo")) { SPContext.Current.Web.Site.RootWeb.Properties.Add("MyInfo", xml); SPContext.Current.Web.Site.RootWeb.Update(); } else { SPContext.Current.Web.Site.RootWeb.Properties["MyInfo"] = xml; SPContext.Current.Web.Site.RootWeb.Update(); } SPContext.Current.Web.Site.RootWeb.AllowUnsafeUpdates = false; SPContext.Current.Web.Site.RootWeb.Update(); SPUtility.Redirect("RedirectToErrorPage/ApplicationPage1.aspx?ExInfo=" +xml, SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current); Redirected page code: if (SPContext.Current.Web.Site.RootWeb.Properties["MyInfo"] != null) { using (SPWeb web = SPContext.Current.Site.OpenWeb(SPContext.Current.Web.Site.RootWeb.Url)) { TextBox1.Text = Convert.ToString(SPContext.Current.Web.Site.Root

'AllowUnsafeUpdates' property on SPWeb - Ask urgently for assistance!

<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } --> Hi all, since two days I look without success for a solution for an update, which because of - Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb. - can not be accomplished. My assumption is that the error could have to do something with the implemented context. I am missing the necessary know-how to limit the Error. Would be grateful for each assistance! Thank you in advance.     The Exception ist thrown in this function (at roleAssignments.Add(roleAssignment); ):   //create role deinition for the customer public void DefineCustomerRole() { SPSecurity .RunWithElevatedPrivileges( delegate () { using ( SPSite spSite = this .GetSetCurrentSite) { using ( SPWeb spWeb = this .GetSetCurrentWeb) { // Break permission level inheritance if exists, than set new permissions if (!spWeb.HasUniqueRoleDefinitions) spWeb.RoleDefinitions.BreakInheritance( true , true );   string CustomGroupName = this .GetSetCustomGroupName; SPRoleDefinitionCollection roleCollection = spWeb.RoleDefinitions; SPRoleAssignmentCollection roleAssignments = spWeb.RoleAssignments; SPWeb spWebRoot = spWeb.Site.RootWeb; spWeb.Update(); spWebRoot.AllowUnsafeUpdates = true ; spSite.AllowUnsafeUpdates = true ; SPWebApplication webApp = spWe
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend