Inserts to Database During Debugging Does Not Comm

2019-09-03 16:54发布

问题:

Sorry about this but for the life of me I can't figure it out, I'm sure it must be a setting within visual basic that I am missing.

So I have a program that lets me insert values into my database and a datagridview that selects those values thus showing me the results of my inserted records.

When I debug my program it looks great. Everything inserts and shows up in the datagridview. The only problem is as soon as I close the program the records disappear. When I enter the program again they are not there. When I examine the actual database the values say they didn't commit.

What confuses me the most is that this was working fine yesterday and I haven't touched the any of the visual basic settings so I have no idea what could be causing this problem.

Thank you in advance for all of your help.

Edit

so I figured out that it was because a property of the database named "Copy to Output" was set to "copy always" and that by setting it to "copy if newer" fixed the problem. I am now seeing that visual studio is making the changes to its own copy of the database within the debug/bin folder. Is there anyway to make it commit to the actual database instead of going around it like that?

Here is my connection string:

<add name="SA_DBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;|DataDirectory|\SA DB.mdf&quot;;Integrated Security=True;User Instance=True; MultipleActiveResultSets=True"
        providerName="System.Data.SqlClient" />

回答1:

I just spend an entire morning trying to figure this out. Turns out that when you start debugging the database file is copied to the debug-folder and THAT file is updated.Not the file in your solution-folder.

So it was working al along.

https://blogs.msdn.microsoft.com/vsdata/2009/07/30/debugging-with-local-database-file/

PS. Have to give credit to @Ryoku for answering this in the edit of his questiong though. Just figured I'd post this anser everhwere I can.