问题描述
最近我在 SQL Server 2008 R2 数据库上工作.我在我的应用程序中创建数据库并附加相同数据库的 .mdf 文件,其中包含一些默认数据.运行应用程序默认数据正常.现在我在我的应用程序中插入、更新一些数据并且它工作正常.但是当我退出应用程序并再次运行应用程序时,最后添加和更新的数据会丢失,但默认数据会像以前一样正确.请帮忙.为什么是新的
Recently I work on SQL Server 2008 R2 database. I create database and attach .mdf file of same database in my application with some default data in it . Run application default data coming properly. Now I insert, update some data in my application and its works fine. But as I exit application and again run application lastly added and updated data get lost but default data coming proper as earlier. Please help. Why new
推荐答案
正如@Henk, @Microtechie 提到的,我扫描了我的项目文件夹,发现那里有3个.mdf文件副本,第一个在项目文件夹中代码project([ProjectFolder ]) 在 [ProjectFolder]/bin/debug 文件夹中排名第二,在 [ProjectFolder]/bin/release 文件夹中排名第三,突然解决了我的问题.问题不在项目文件夹中的多个 .mdf 文件中,因为我每次清理"和构建"我的解决方案时,来自 [ProjectFolder] 的 .mdf 文件的新副本被复制到 [ProjectFolder]/bin/debug 文件夹中,导致覆盖同一文件夹中的最后一个 .mdf 文件.因此,每次我构建和运行应用程序时,只会丢失默认数据以及最后添加和更新的数据.谢谢大家的回复和准确的回答..!
As mention by @Henk , @Microtechie , I scan my project folder and found there are 3 copies of .mdf file are there, 1st in project folder where code project([ProjectFolder ]) resides 2nd in [ProjectFolder]/bin/debug folder and 3rd in [ProjectFolder]/bin/release folder and suddenly solution to my que trigger in my mind. Problem not in multiple .mdf files in project folder, as I every time ‘Clean’ and ‘Build’ my solution new copy of .mdf file from [ProjectFolder] get copied into [ProjectFolder]/bin/debug folder, result in override of last .mdf file in same folder. Hence every time I build and run application only default data coming and last added and updated data get lost. Thanku all for your replies and precise answer..!
这篇关于退出应用程序时 .mdf 文件中的数据丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!