A strong dataset cannot be updated when the MDF file of sqlserver is directly attached to it-Cause Analysis

Source: Internet
Author: User
During the demonstration of layer-3 architecture development for my students, I used winform in vs2005 to establish the Dal, BLL, and uilayer-3 architectures, and used strong datasets in the Dal layer, bll layer processing logic. ProgramAfter running, the update, insert, delete, and other operations on the tableadapter take effect. Then I observe the MDF file and the data is not updated. when winform is disabled and winform is restarted, it is found that the modification only affects strong datasets, but the datasets are not eventually reflected in the MDF file. the Return Value of the tableadapter method call indicates that my method is successful!
Environment:
1. Create the app_data directory under the project, place the MDF file, and double-click the MDF file to mount the MDF to sqlserver express using attachdbfilename;
2. Add a new dataset, drag the table in 1 to dataset to generate a strong dataset, and then build the tableadapter method set and BLL layer of the Dal layer to complete the system.

Debugging found that every time I run winform, the system copiesSource codeThe app_code directory of the CS file at the same directory is under the bin directory, and the MDF file under the bin directory is connected.
In this way, I will overwrite the bin \ app_code \ *. MDF file every time I run it. Naturally, I cannot modify it. It's really depressing!

Mount the MDF file directly to sqlserver. Modify the settings file to connect to the MDF file instead of the MDF file in sqlserver mode. The program is normal!

If debugging is not performed, directly copy the items under the bin directory during release. It is estimated that there will be no problem. Or we can consider placing the app_code directory under the bin directory instead of the Cs source.CodeFile at the same directory level. this is because I considered that there was no problem in Asp.net and followed winform. this is also natural. The connection group is very internal database = | datadirectory | \*. MDF represents the current path in webform, and it is indeed the bin directory in winform.
So be careful. Haha

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.