SQL Access to Configuration DB required
In many cases you pass an URL string to connect to SharePoint. In my case I wanted to verify the URL by using this code:
1: Uri requestUri;2: if (!Uri.TryCreate(absoluteUrl, UriKind.Absolute, out requestUri))3: throw new ArgumentException(absoluteUrl + " is no a valid URL.");4:5: SPWebApplication webApplication = SPWebApplication.Lookup(requestUri);And here comes the “but”. I did not know that the account, which is executing the code, needs permissions to the Configuration Database!
So
either grant permissions, oruse something like this:1: using (var site = new SPSite(requestUri.AbsoluteUri))2: {3: SPWebApplication webApplication = site.WebApplication;4: }Happy SharePointing…