title: How can I create .MDF file based on existing Database in SQL Server?
body: <p>I have a database which is sitting on my local PC. I want to create a <code>.mdf</code> file based on this database. I created an empty <code>.mdf</code> file in Visual Studio. How to connect SQL Server Management Studio and run queries against it? </p>
  
  <p>But I want to create <code>.mdf</code> file based on existing database which will save me time on rebuilding whole DB in Visual Studio and also it will have all of the data in tables.</p>
  
  <p>I <a href="http://msdn.microsoft.com/en-us/library/ms233763%28v=vs.90%29.aspx" rel="nofollow">check</a> this link. it is not  helping me solve my question.</p>
  
  <p>Also was trying to copy <code>.mdf</code> file from <code>C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA</code> into my project in <code>App_Data</code> folder but it trowing error <code>cannot complete because file is used by SQL Server</code><br>
  Thank you.</p>