Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my SQL Server data deleted when application stopped?

I have one table in SQL Server that contains datetime columns. I use LINQ to SQL.

While running the program all data is saved in a table and I get all the results properly.

But as soon as I close the run, there is no data in the table and the getall function returns null.

I can not find the problem.

The code to insert data into a table is:

public bool AddTime(WorkTime ToAdd)
{
    try
    {
        _context.WorkTimes.InsertOnSubmit(ToAdd);
        _context.SubmitChanges();
    }
    catch (Exception)
    {
        return false;
    }
    return true;
}
like image 528
zeevblu Avatar asked Apr 30 '26 16:04

zeevblu


1 Answers

Most likely, you using a SQL Server Express Edition standalone file, that is getting re-deployed (copied to the output folder) every time you build.

Options:

  • register a database inside the engine itself, rather than using a standalone file, or
  • take care not to overwrite your database when you build
like image 98
Marc Gravell Avatar answered May 03 '26 05:05

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!