Thursday, June 26, 2008

Get Config DB from SPSite

I have got on SharePoint forum how to get the config database from SPSite

using Microsoft.SharePoint;

using Microsoft.SharePoint.Administration;

  using (SPSite site = new SPSite("http://basesmcdev/tester1"))

                SPProcessIdentity pi = site.WebApplication.Farm.TimerService.ProcessIdentity;
                string userName = pi.Username;
                object configDB = pi.GetType().GetProperty("ConfigurationDatabase", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(pi, null);
                SPServer server = (SPServer)configDB.GetType().GetProperty("Server").GetValue(configDB, null);
                string serverName = server.Name;

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.