Search code examples
sqlfileinsertmdf

Copy mdf file and use it in run time


After I copy mdf file (and his log file) I tries to Insert data. I receive the following message:

"An attempt to attach an auto-named database for file [fileName].mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

When I copied the file manual everything worked normally. Is it correct the order File.Copy leaves the file engaged?


Solution

  • Make sure you don't have a connection open to the mdf file when you copy it. This might be related to there being only one lock file for the two copies.