Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My function requires an iis reset every 15-20 requests 1

Status
Not open for further replies.

efree47

Programmer
Sep 28, 2010
7
0
0
US
My function requires an iis reset every 15-20 requests.
I created this CLR class to pull data from my web service. Every 15-20 times it run it requires an IIS reset. Am I missing a dispose someplace? See code below

Code:
public class SharePointCalendar
    {
        [SqlFunction(SystemDataAccess = SystemDataAccessKind.Read, FillRowMethodName = "GetCalendarItemInfo")]
        public static IEnumerable GetCalendarItems(SqlString url, SqlString listName)
        {
            DataTable t = new DataTable();
            WindowsImpersonationContext ctx = null;

            WindowsIdentity id = SqlContext.WindowsIdentity;

            try
            {
                ctx = id.Impersonate();

                WSS.Lists svc = new WSS.Lists();
                svc.Url = url.ToString();
                svc.Credentials = CredentialCache.DefaultNetworkCredentials;
                XmlNode node = svc.GetListItems("Leasing Overview", null, null, null, "100000", null, null);
                XmlTextReader rdr = new XmlTextReader(node.OuterXml,XmlNodeType.Element, null);
                DataSet ds = new DataSet();
                ds.ReadXml(rdr);
                t = ds.Tables[1];
            }
            finally
            {
                if (ctx != null)
                    ctx.Undo();
            }

            return t.Rows;
        }

        public static void GetCalendarItemInfo(
                            object obj,
                            out SqlString SiteID,
                            out SqlString PropName)
        {
            DataRow r = (DataRow)obj;
            SiteID = new SqlString(r["ows_Site ID"].ToString());
            RLM = new SqlString(r["ows_prop name"].ToString());  
        }
    }
 
your are not disposing the WindowsImpersonationContext or XmlTextReader. wrap them in a using block to ensure they are properly disposed. this is the first place to start. try profiling the service as well, using a tool like Ants Profiler or dotTrace. this will help you analyze what's happening.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Didnt know you could Dispose the xmltxtreader, the ctx.Undo runs the dispose in sharepoint. When i did that to the xmltxtreader it seems to work. Thank you very much!
 
ctx.Undo runs the dispose in sharepoint.
actually it doesn't. it resets the current context to the original state, but it does not dispose of the context. 2 different things.
sharepoint and .net are 2 separate things. .net is a framework, sharepoint is an application. sharepoint doesn't change how .net works Undo in a pure .net application isn't different than Undo in sharpoint. sharepoint simply uses the .net framework.

IDisposable is one of the most powerful interfaces in .net. right there with IEnumerable's deferred execution.
Code:
using(var disposable = new object implementing IDisposable)
{
   ...
}
is syntax sugar for
Code:
IDisposable disposable = null;
try 
{
   disposable = new object implementing IDisposable
   ...
}
finally
{
   if(disposable != null)
   {
      disposable.Dispose();
   }
}
just about any object which implements IDisposable does so to handle resource cleanup in the event of an exception. fore example
Code:
using(var disposable = new object implementing IDisposable)
{
   throw exception
}
will clean up after itself in the finally block even though an exception was thrown.
Code:
var disposable = new object implementing IDisposable
throw exception
disposable.Dispose();
in this example Dispose will never be called because the exception is will abort the call stack.

hopefully this clear's things up for you.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top