在调试过程中插入数据库不会提交到实际的数据库 [英] Inserts to Database During Debugging Does Not Commit To The Actual Database

查看:306
本文介绍了在调试过程中插入数据库不会提交到实际的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,但是对于我的一生,我无法弄清楚,我确定它一定是我所缺少的Visual Basic中的设置.

所以我有一个程序,可以将值插入到数据库中,还有一个datagridview,它可以选择这些值,从而向我显示插入记录的结果.

当我调试程序时,它看起来很棒.一切都会插入并显示在datagridview中.唯一的问题是,一旦我关闭程序,记录就会消失.当我再次进入程序时,它们不在那儿.当我检查实际的数据库时,值表明它们没有提交.

最让我感到困惑的是,昨天它运行良好,而且我还没有触摸任何视觉基本设置,所以我不知道是什么原因导致了这个问题.

在此先感谢您的帮助.

修改

所以我发现这是因为名为复制到输出"的数据库的属性设置为总是复制",并且通过将其设置为如果更新则复制"可以解决该问题.我现在看到Visual Studio正在对其在debug/bin文件夹中的数据库副本进行更改.无论如何,有没有使它提交到实际数据库的方法,而不是像那样处理它?<​​/p>

这是我的连接字符串:

<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" />

解决方案

我只花了整个上午的时间来解决这个问题.事实证明,当您开始调试时,数据库文件将被复制到调试文件夹,并且该文件将被更新.而不是解决方案文件夹中的文件.

所以一切正常.

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

PS.但是必须感谢@Ryoku在编辑他的问题时回答了这个问题.只是想想我会尽一切可能发布这个分析器.

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" />

解决方案

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.

这篇关于在调试过程中插入数据库不会提交到实际的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆