title: Directory.Copy fails because *.mdf is being accessed by another process in C#
body: <p>I am building a <code>winform</code> based Desktop application in C#. I am using SQL Server Database in my application.</p>
  
  <p>The application has an option of taking an archive, where I basically copy all the configuration files and data files ( *.mdf) into a Winzip Archive.</p>
  
  <p>However, I am not able to copy the Database file *.mdf. It throws an exception : </p>
  
  <p><strong>"The process cannot access the file UserData.mdf because it is being used by another process"</strong></p>
  
  <p>I believe I am closing all the SQL connection, and perform manual Garbage collection  via
  <code>GC.Collect()</code>.</p>
  
  <p>But, this doesn't seem to work. </p>
  
  <p>As a workaround, if I am able to kill the process sqlservr.exe from the Taskmanager, the file copy works fine.</p>
  
  <p>I guess, there should be a better and a more elegant way of doing it. Any Idea how to proceed ?</p>
  
  <p>Thanks
  Kiran</p>