Determine Sharepoint version using SQL query on the Sharepoint config database

We recently had a client who lost their Sharepoint application (web front-end) server, fortunately their Sharepoint databases were located on a different SQL server (which was being backed up). So we started to rebuild the Sharepoint application server & proceeded to restore the content (websites).

When we ran through the Sharepoint configuration wizard which connects the application server to the Sharepoint config database it failed at step 2 with the following error:
“failed to connect to the configuration database an exception of type system.security.securityexception was thrown.
Additional exception information: access denied”

This seemed strange since we were definitely using the correct Sharepoint database user, to be sure we verified the permissions were correct in SQL. It turned out the problem is caused by the Sharepoint config database version running a slightly different version to the application server (they need to be exactly the same).

How did we determine the Sharepoint version of the configuation database then?

Simple…..

The first way is to open a web browser and got to the site settings page (Site Actions > Site Settings > Modify All Settings).

The second method is to run a query against the databases.  Open SQL Server Management Studio, Connect to the server, new query, run the following:

SELECT [VersionId]
      ,[Version]
      ,[Id]
      ,[UserName]
      ,[TimeStamp]
      ,[FinalizeTimeStamp]
      ,[Mode]
      ,[ModeStack]
      ,[Updates]
      ,[Notes]
  FROM [SharePoint_Config].[dbo].[Versions] 
  WHERE VersionId = ‘00000000-0000-0000-0000-000000000000’ 
  ORDER BY Id DESC

 This returns:

VersionId Version Id UserName Updates
00000000-0000-0000-0000-000000000000 12.0.0.6219 4 MOSS\user 3
00000000-0000-0000-0000-000000000000 12.0.0.4518 1 MOSS\user 2

The top row is the latest version, if you have changed the database name from “SharePoint_Config” be sure to update the query to reflect the correct name. Check out this site to see what version you are running.

Once we determined the correct version we created the slipstreamed Sharepoint installation required, re-ran setup and bang everything worked correctly!

Jason Vigus

Recover a deleted Sharepoint site collection from SQL backup (2007/2010)

Lets assume you have NOT been doing Sharepoint site collection backups but you do have SQL database backups. Either the Sharepoint front end web server has died and you have reinstalled a new copy of Sharepoint without your sites loaded:

1. Create a new SQL database & restore your backup into it.
2. At the command prompt use stsadm.exe to add the content database to your new site:
stsadm -o addcontentdb -url http://yourwebapp:port -databasename yourcontentdb -databaseserver yoursqlserver
3. Perform an IISRESET
4. Your all done, load the url and bath in your awesomeness!

Jason Vigus