Saturday, June 13, 2009

Rebuilding System Databases (/cry)

So, I spent about 4 hours between last night and this morning troubleshooting an issue with one of my SharePoint machines. The master SQL database had somehow become corrupted and the service would not start. When you attempt to start it you get the following error in the event log:

Event Type: Information
Event Source: MSSQLSERVER
Event Category: (2)
Event ID: 3417
Date: 6/18/2008
Time: 5:19:25 PM
User: N/A
Computer: SERVER_NAME
Description:
Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup, repair it, or rebuild it. For more information about how to rebuild the master database, see SQL Server Books Online.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
Data:
0000: 59 0d 00 00 0a 00 00 00 Y.......
0008: 0d 00 00 00 41 00 54 00 ....A.T.
0010: 4c 00 53 00 50 00 53 00 L.S.P.S.
0018: 44 00 30 00 31 00 56 00 D.0.1.V.
0020: 30 00 34 00 00 00 00 00 0.4.....
0028: 00 00
..

In order to repair the master database I had to invoke the setup.exe from the install disk from the command line. The syntax to do this is as follows:

start /wait \sqlfoder\setup.exe /qb INSTANCENAME=[instance] REINSTALL=SQL_Engine REBUILDDATABASE=1 SAPWD=[strong_password]

The only issue with this is that if you have installed any of the service packs (which you should have) then that statement gives you the following error:

Installation package for the product SQL Server 2005 (64bit) cannot be found. Please locate a valid SQLRUN_SQL.MSI

After some searching I found the solution and it is to first run this command:

\sqlfoder\setup.exe /qb INSTANCENAME=myinstance REINSTALL=SQL_Engine REINSTALLMODE=v

After that succeeds you can run the normal rebuild database command listed above and it will succeed as well.

Now all you have to do is reattach all of your databases and you are good to go!