locked
Farm, SPWebApplication.Lookup, System.InvalidOperationException

    Question

  • Dear all,

     

    I have a piece of code that works well on a standalone SharePoint installation:

     

    public void SetPeoplePickerProperty(string webAppUrl) {

    // elevate permissions to allow setting of property.

    SPSecurity.RunWithElevatedPrivileges(delegate() {

    System.Uri srvrUri = new System.Uri(webAppUrl);

    SPWebApplication webApp = SPWebApplication.Lookup(srvrUri);

    if (!webApp.PeoplePickerSettings.OnlySearchWithinSiteCollection) {

    webApp.PeoplePickerSettings.OnlySearchWithinSiteCollection = true;

    webApp.Update();

    }

    });

    }

     

    When I deploy it to a server farm, I get the following error:

    System.InvalidOperationException: This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products and Technologies Configuration Wizard, located on the Start menu in Administrative Tools.
       at Microsoft.SharePoint.Administration.SPWebApplication.Lookup(Uri requestUri)

    The user running the query is farm administrator. It has the necessary access to the configuration database. The server running the code is joined to the farm.

     

    Ideas anyone?

     

    Thanks,

     

    Tore.

    Sunday, August 26, 2007 3:30 PM

Answers

  • I had to set the application pool identity to a user with appropriate permissions. I had an impersonation section for this user in my web.config, but this did not do the trick.

    Sunday, August 26, 2007 7:19 PM

All replies

  • I had to set the application pool identity to a user with appropriate permissions. I had an impersonation section for this user in my web.config, but this did not do the trick.

    Sunday, August 26, 2007 7:19 PM
  • What are the apropriate permissions?

    I have the same exception, but my user is granted whatever permission i can think of

    Thank you
    Wednesday, September 3, 2008 8:56 AM
  • I used following code to get the web application.

    SPWebApplication spWeb = new SPSite(URL).WebApplication();

    This is working on all my environments...

    Hope this helps :)
    Friday, March 5, 2010 5:55 AM
  • Thanks.

    After changing the target type to Any CPU worked for me.

    Thursday, May 5, 2011 12:27 PM