none
sdf file in debug and release folders gets new data but the one in the project folder does not?

    Question

  • Hi all,

    I have a personal program that uses a compact database 3.5. The server explorer shows the connection to the database and I can see the location folder is:

    C:\Users\myUserName\Documents\Visual Studio 2010\Projects\C_sharp\myProject\myProject\myData_DB.sdf

    I've noticed that I'm loosing data sometimes and I just figured that the new data is going to the sdf file in the debug (or release) folder in the project and not to the above location. I read that a property, "Copy to Output Directory", has to be set to "Copy if newer" and it is. But the file in the path above is not being updated. What is the problem?

    BTW I see two dataset files in the project and I only created one of them so I may have messed up something in there. I'm learning about datasets, data tables and table adapters so I could have dragged something to the wrong place :-(. Oh, and I copied the database from a previous version of the program and renamed it in the new location. I keep messing up so I just start over ... third time was not the charm :-). 

    Thanks

    Tuesday, July 16, 2013 4:39 PM

Answers

  • The problem is that your connection string is not pointing to the file in the project folder, but contains the DataDirectory macro, which makes it relative. Fix is to not include the file in your project, or make the connection string have the full path. 

    Please mark as answer, if this was it. Visit my SQL Server Compact blog Windows 8 Apps Showcase

    • Marked as answer by DSP1024 Thursday, July 18, 2013 4:03 PM
    Wednesday, July 17, 2013 6:38 AM
    Moderator

All replies

  • The problem is that your connection string is not pointing to the file in the project folder, but contains the DataDirectory macro, which makes it relative. Fix is to not include the file in your project, or make the connection string have the full path. 

    Please mark as answer, if this was it. Visit my SQL Server Compact blog Windows 8 Apps Showcase

    • Marked as answer by DSP1024 Thursday, July 18, 2013 4:03 PM
    Wednesday, July 17, 2013 6:38 AM
    Moderator
  • Hi,

    I found an application setting for the connection string set to the following:

    Data Source=|DataDirectory|\myData_DB.sdf

    I changed it to:

    Data Source=C:\Users\myUserName\Documents\Visual Studio 2010\Projects\C_sharp\myProject\myProject\myData_DB.sdf

    Is that it? in the future, how do I avoid this problem?

     Thank you.

    Wednesday, July 17, 2013 5:44 PM
  • Thursday, July 18, 2013 6:25 AM
    Moderator
  • I see that I still have much to learn about this.

    Thanks for the solution. Take care.

    Thursday, July 18, 2013 4:04 PM
  • I am too facing the same problem. when I debug the application , the database file is automatically moved to Debug Folder in the Bin directory of the Application. The Changes are committed as long as the application is open. As soon as ia stop debugging the application, the changes are rolled back. I think it just males the changes in the debug folder's database file and not in the database that is in the Application folder. What to do under these circumstances? For deploying the application Where should the database file be placed?
    Sunday, November 03, 2013 5:06 PM