none
MDF Fails to find its way to Bin/Debug folder RRS feed

  • Question

  • This is the error that I get;

    An attempt to attach an auto-named database for file c:\Projects\Test2\Bin\Debug\Test2.mdf failed. A database with the same name exists, or specified file cannot be opened, or is located on UNC share.

    There is no database file in the Debug folder, it's in the project folder. I can copy the database file to the Debug folder and things work properly. With that being said, here's the history. I initially created a Test1 project, added a data source, created a custom table adapter based on some SQL statements, added a datagrid with the navigator and so forth. Everything worked fine. Later after working through some scenarios in my test1 project it was time to create, what I'll call my production project. Following the same procedures I recreated many of the features found in the test project. When running in debug this is when the above message started. I note that a copy of the database file found it's way into the debug folder on the test1 project, but no such thing occured on the latter project. I shouldn't have to manually copy this file to Debug. I cannot find a setting or anything that makes this happen. I've been working this issue for hours now and I'm stumped. I'd appreciate some help with this as I'm sure that my database will be going through several revisions.

     

    Tuesday, September 21, 2010 10:25 PM

Answers

  • If you look at the properties on the mdf file there is a setting Copy to Output Directory set this to Copy Always or Copy if Newer
    www.sqlquerybuilder.com
    If I answered your question please mark my post as the answer.
    • Marked as answer by Peak Creek Wednesday, September 22, 2010 4:18 PM
    Wednesday, September 22, 2010 1:40 AM

All replies

  • If you look at the properties on the mdf file there is a setting Copy to Output Directory set this to Copy Always or Copy if Newer
    www.sqlquerybuilder.com
    If I answered your question please mark my post as the answer.
    • Marked as answer by Peak Creek Wednesday, September 22, 2010 4:18 PM
    Wednesday, September 22, 2010 1:40 AM
  • Ok, I see the option for 'Copy to Output directory' on the DataSet.xsd file. I don't see such an option on the mdf file. I set the xsd file to 'Copy Always' and I still get the same error message.
    Wednesday, September 22, 2010 1:43 PM
  • Ok Lee,

    I think I have got this all straightened out. I used the SSEUtil to find all copies of my database. In my effort to start my production project and further resolve this problem, I had moved the project folder around, made copies of the db, deleted copies of the db, and so forth. I was able to restore the various projects via the Recycle Bin restore function. I made connections to the db in all the orphaned projects, detached the db, and then disconnected from the db. I kept doing this until SSEUtil reported no more copies of my database file. I then deleted all the projects that had any reference to my db file. Now that I've cleaned up the mess I was able to go to my production project and do some maintenance there. I had many disassociations with various binding controls and wasn't able to restore the associations. I basically cleaned the clock by deleting all my table adapters, deleting the XSD file, until there were no more references to the db. I also had to manually clean out some of the form load code that had been automatically generated. With all that being done, and starting from a clean slate, I was able to recreate my table adapters, create my custom adapter, insert a datagrid and now things work as they should. I had mentioned in my previous post that the mdf file didn't have a property to 'Copy to Output directory'. Since I've cleaned up everything it now has that property. What a royal pain, but no doubt this was my own fault. Moral of the story is to exercise caution when copying and/or deleting these database files.

    Thank you for your help.

    • Edited by Peak Creek Wednesday, September 22, 2010 4:47 PM spelling
    Wednesday, September 22, 2010 4:40 PM