I recently responded to a thread on Twitter (
http://www.twitter.com) offering to describe a method of detecting whether a SQL server hosts a SharePoint farm. Several folks followed up asking for a blog on how to do this so here goes. Note: This is the same for 2007 and for 2010
Consider the way PSConfig identifies a Configuration Database when you try to join a server to an existing farm.
Once you choose to join an existing farm, you will then be asked to specify a database server. At that point you have the option of retrieving the database names of every configuration database on that server so that you can choose the farm you would like to join.
The database name field is populated by issuing the following SQL command from the WFE to the SQL Server:
SELECT name FROM sysdatabases WHERE has_dbaccess (name) = 1
The server responds with a list of all databases to which the logged in user has access.
In order to determine which databases are configuration databases, the following SQL query is used:
In this case the VersionId that SharePoint is trying to match is:
60B1F2BE-5130-45AB-AF1D-EDD34E626B5D
Only a configuration database will have a row that matches this GUID although you will find a Versions table in all SharePoint databases.
Once the information requested is provided, clicking Next will perform the following actions.
The database id is determined using the friendly name for the database.
SELECT @dbid = db_id(@databaseName)
Next, SharePoint will read in the application settings that are related to the farm to be connected to. Once that is complete, the configuration wizard will display a final confirmation before performing the configuration.