I'm building a .NET Health Analyzer Custom Rule which checks a few vital signs of another custom application I have built, however if the application is also deployed on a server that is also hosting SQL Server AND the configuration database, there's a few checks I don't want to run (don't ask why, long story, mostly performance related). How can I determine via API where the Config database is actually located in SharePoint 2010?
This was nice quest for me. I will not ask why do you need this and I hope that you don't need warning like:
I didn't found many articles on net covering this specific issue (no wonder when it is bad practice). The only one was 2007 related: Determining the Configuration Database in a SharePoint 2007 Farm. Check it out.
I came up with this piece of code:
So after few foreachs and few ifs you have SPDatabase object containing config database. I have tested it against my local SP and it works. I will not exclude there can be some issues in different environment and that there is maybe better way to do this.
Did I mentioned it before that even if you just take a look at hardware responsible for SharePoint database you can end up with some unexpected behavior?