Test Whether SharePoint Server Is a Database Server

The SPServer object is pretty useful when you are interrogating topological elements in your farm for different types of information. One of the thing that I test a lot when writing security / admin utilites for companies is the roles and stuff that are running on the box, the most is whether it is a database server or not. Consider the following IsSqlServer method, that uses the SPServerRole enumeration with the SPServer.Role property along with service instance testing ala SPDatabaseServiceInstance.

[csharp]

private bool IsDatabaseServer(SPServer server)

{

if (server.Role.Equals(SPServerRole.Invalid))

{

while (server.ServiceInstances.Count > 0)

{

foreach (var instance in server.ServiceInstances)

{

if (instance is SPDatabaseServiceInstance)

{

return true;

}

}

break;

}

}

return false;

}

[/csharp]

Share

One Comment

  1. Vishnu says:

    Helpful piece of code when building SharePoint administrative tooling.

Leave a Reply

Your email address will not be published. Required fields are marked *