You are here: Home » Extract a single version of a file from a MOSS SQL Server Database

Extract a single version of a file from a MOSS SQL Server Database

Posted by mindy
No Comments »

I recently ran into a situation where MOSS was unable to open a particular historical version of a document in a document library. One example of an error was, right-clicking and choosing 'Save Target As…' in Internet Explorer yielded: "Internet Explorer cannot download <file name> from <portal name>. Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later."

Helpful, right?

So I went in search of a method to extract this file from SQL. I found this VB Script: http://blogs.msdn.com/field_notes/archive/2008/06/23/recover-documents-from-moss-2007-database.aspx?CommentPosted=true#commentmessage which extracts the current version of a document, but that's not what I needed.

I next did a SQL query to find all versions of the document:

SELECT dbo.AllDocs.TimeLastModified, dbo.AllDocs.DirName, dbo.AllDocs.LeafName, dbo.AllDocs.Version, dbo.AllDocStreams.Content
 FROM dbo.AllDocs
 INNER JOIN dbo.AllDocStreams
 ON dbo.AllDocs.ID = dbo.AllDocStreams.ID
 AND dbo.AllDocs.Level = dbo.AllDocStreams.Level
 where dbo.AllDocs.LeafName='file name'

Using the TimeLastModified column I identified the version # that I needed.

I then replaced 'AND IsCurrentVersion=1' in the script with 'AND dbo.AllDocs.Version=<version number from the column>' and successfully extracted the supposedly corrupt file that I needed!

Your email is never shared.
Required fields are marked *




Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>