1

I have created a database with several tables, and I also created a C# Windows forms application. Occasionally, after testing the application, I will find tables empty that were filled using the application (and stayed full upon several further testing - data can also be seen on vs server explorer => show table data).

Not only are tables empty but the only data that I do access when this occurs is data that I have entered from a long time ago and I have deleted (while I was testing deleting from my tables).

I have put using{ ... } around all my code that connects to databases, It is a one off event , if I run the code, edit some of table data in the application, the database will change, then if I will run again and the data will be updated from the last run, several times later - randomly the data will go missing...

My connection string points to the file in my output directory, my database copies if newer. VS 2017, if you need anymore information I will edit

Anyone got any leads?

For school coursework

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Daniel Loudon
  • 799
  • 3
  • 18
  • If there was such a bug, people would have noticed 15 years ago. Don't look for ghosts. Look for bugs in your code. You are either using the wrong connection string or loading it from an old settings file. It's impossible to tell what's wrong since you don't provide any code or explain what the code does. – Panagiotis Kanavos Nov 06 '17 at 14:21
  • Oh - SQL is new to me, I created the database in visual studio so I think it's SqlServer, I think I should only edit the output one may this be the problem, I have both databases open and one of them contains more data than the other, the one that isn't in my output directory seems to contain the data that I mysteriously see every now and again... – Daniel Loudon Nov 06 '17 at 14:22
  • Are you using user-instance databases perhaps? These point to *files*, not database servers. These databases are *copied* from your source folder into your debug folder each time you start debugging. The feature is also *deprecated*, so you shouldn't use it – Panagiotis Kanavos Nov 06 '17 at 14:23
  • @DanielLoudon SQL works What is your connection string? Does it contain a `AttachDbFilename` keyword? – Panagiotis Kanavos Nov 06 '17 at 14:24
  • Yes i don't think it's best but this is for a piece of coursework and I've no choice but to do it this way... – Daniel Loudon Nov 06 '17 at 14:24
  • @DanielLoudon then find a better course. This is [deprecated for over 5 years](https://stackoverflow.com/questions/11178720/whats-the-issue-with-attachdbfilename). It's also a duplicate of other questions – Panagiotis Kanavos Nov 06 '17 at 14:25
  • I cant find a better course, its my A level and I need to complete it for school otherwise i will fail, my whole class and 100s of other students take this A level and we all are in the same boat, its silly, also my connection string looks like this _MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Even_ – Daniel Loudon Nov 06 '17 at 14:27
  • I will edit question, shall i stop updating the database in the output directory or have i came too far and just keep going with the way it is – Daniel Loudon Nov 06 '17 at 14:31
  • 1
    that *is* [a user-instance database](https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/sql-server-express-user-instances). Such databases are stored in your source folder during development and *copied* to your debug/release folder when you run your code, overwriting anything that's stored in there. There's nothing wrong. There's no "old" database. If you want to add data to your dev database, the correct file is in your source folder – Panagiotis Kanavos Nov 06 '17 at 14:31
  • Ok so I continue to add to the database thats in the output directory and just leave the source one alone – Daniel Loudon Nov 06 '17 at 14:36

0 Answers0