title: How do I get the internal SQL Server database version number of an .MDF database?
body: <p>I would like to get the internal database version number of a SQL Server database programatically to determine which SQL Server instance to use. </p>
  
  <p>i.e. SQL Server 2008 - Version 661, SQL Server 2008 R2 -  Version 665</p>
  
  <p>I have found an article: <a href="http://rusanu.com/2011/04/04/how-to-determine-the-database-version-of-an-mdf-file/" rel="nofollow">http://rusanu.com/2011/04/04/how-to-determine-the-database-version-of-an-mdf-file/</a> that shows the location of the version number as the DWORD value at offset 0×12064 in the <code>.mdf</code> file.</p>
  
  <p>How can I get this information programatically?</p>
  
  <p>Thanks</p>