title: How do I copy SQL Server 2008 database via C# code
body: <p>I want to copy an existing SQL Server 2008 database schema, but not the data, to a new database on the same server (i.e MyDB => MyDB_Test) using C#.  </p>
  
  <p>I found some sample code at <a href="http://www.codeproject.com/KB/cs/CopyDBSchemaUsingSMO.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/cs/CopyDBSchemaUsingSMO.aspx</a> that seems to do exactly what I want but it kept throwing the following error on the ddatabase.Create() line:</p>
  
  <blockquote>
  <pre><code>Could not load file or assembly 'Microsoft.SqlServer.BatchParser,
  Version=9.0.242.0, Culture=neutral,
  </code></pre>
    
    <p>PublicKeyToken=89845dcd8080cc91'
        or one of its dependencies. The system cannot find the file
        specified.":"Microsoft.SqlServer.BatchParser,
    Version=9.0.242.0, 
        Culture=neutral, PublicKeyToken=89845dcd8080cc91"</p>
  </blockquote>
  
  <p>I tried to find the missing DLL but I was only able to find a version for SQL Server 2005.  I'm not sure if I should use that, look for an alternate download or take an entirely different approach.</p>
  
  <p>Any help would be greatly appreciated!!</p>