0

I have a Winforms application and I added a local database (SQL Server Compact Edition 3.5) to the project.

I added tables and so on.

Also, I added an Entity Data Model to the project, selected Generate from database, then selected the connection string that visual studio offered:

Data Source=|DataDirectory|\SBDATA.sdf

Then, I checked all tables from the database and built my project. So far so good.

In my form I have written this code for AddFolderButton_Click :

using (SBDATAEntities de = new SBDATAEntities())
{
    Folders f = new Folders();
    f.Description = folderDescription;
    f.Path = folderPath;
    f.Mask = folderMask;

    de.AddToFolders(f);
    de.AcceptAllChanges();
    de.SaveChanges();
}

Note that there are more columns in the table but they are accepting null so I think It doesn't matter.

I am getting NO ERRORS, no crash. But when I click on the table in the Server Explorer and choose Show Table Data, I get no records.

Can please someone tell me what am I doing wrong ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
subirshan
  • 323
  • 2
  • 7
  • 20
  • Most likely, the `.sdf` file is being copied to the **output directory** of your project in Visual Studio (`project\bin\debug`) and the rows are being inserted there - but you're checking the file in a different location – marc_s Jul 26 '14 at 09:54
  • @marc_s I have checked and you are right about the file being copied to the output directory. Should it ? And how can I check to be sure that the rows are inserted? – subirshan Jul 26 '14 at 10:06
  • Here you could find a situation like yours and the possible workaround http://stackoverflow.com/questions/17147249/why-dont-changes-to-database-save/17147460#17147460 – Steve Jul 26 '14 at 10:28
  • You need to check the `.sdf` file in the `.\bin\debug` directory - your data being inserted will be stored there, and you should be able to look at that file to verify that. Or alternatively: specify a **full path** in your connection string (instead of the `|DataDirectory|` alias) - then Visual Studio won't be copying around the file anymore – marc_s Jul 26 '14 at 10:39
  • I added another Data Connection from the Server explorer that points to the sdf file in the debug folder. Still no rows in the table. Any ideas why ? @Steve – subirshan Jul 26 '14 at 10:44

0 Answers0