locked
Access Denied error in Execute method of SPJobDefinition RRS feed

  • Question

  • My development environment has WFE and DB service running in a single server.

    I develop my SPJobDefinition with VS2008 & WSPBuilder in the server.

    However, My SPJob always throws out a exception like this: "Access Denied" within its method Execute.

    The code in my Execute method of SPJob is just like this:

    SPSecurity.RunWithElevatedPrivileges (delegate(){
    
    
    
    using(SPSite site = new SPSite("http://myserver"))
    
    {
    
    
    
    using(SPWeb web = site.RootWeb)
    
    {
    
        SPList list = web.Lists["Test"];//Here it will throwes out a error "Access Denied"
    
    }
    
    }
    
    
    
    });
    
    
    
    

    When i comment the code "SPList list = web.Lists["Test"]",it works fine.

    Anybody can tell me how to solve it?

    PS: My Windows Sharepoint Timer is running with local system account.
    Thursday, May 14, 2009 2:24 PM

Answers

  • I'm not TOO sure about this answer, so test it out:

    1. Because it's running in the job service, you may not need to RunWithElevated... remove that block and see if it runs. 

    If not, try #2 (using your existing code):

    2. In SharePoint Central Admin, change the account that runs the job service. Make it a farm admin.

    Daniel Larson, SharePoint MVP, MS Press Author, NewsGator Software Developer Check out my books on Amazon: - Inside Microsoft Windows SharePoint Services 3.0 (with Ted Pattson) - Developing Service Oriented AJAX Applications on the Microsoft Platform (.NET 3.5, WCF, Microsoft AJAX)
    Thursday, May 14, 2009 2:34 PM

All replies

  • I'm not TOO sure about this answer, so test it out:

    1. Because it's running in the job service, you may not need to RunWithElevated... remove that block and see if it runs. 

    If not, try #2 (using your existing code):

    2. In SharePoint Central Admin, change the account that runs the job service. Make it a farm admin.

    Daniel Larson, SharePoint MVP, MS Press Author, NewsGator Software Developer Check out my books on Amazon: - Inside Microsoft Windows SharePoint Services 3.0 (with Ted Pattson) - Developing Service Oriented AJAX Applications on the Microsoft Platform (.NET 3.5, WCF, Microsoft AJAX)
    Thursday, May 14, 2009 2:34 PM
  • It works!
    And i am so sorry that i did not mark your reply as answer timely for my internet service was broken off until today.

    Thanks Paul & Daniel again,you make a great work!
    Sunday, May 24, 2009 2:25 PM