LINQ Confusion - 数据库在应用程序关闭后不会继续存在? [英] LINQ Confusion - Database not persisting after the application closes?

查看:113
本文介绍了LINQ Confusion - 数据库在应用程序关闭后不会继续存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中创建一个WinForms应用程序。当我创建我的数据库对象时,我有两个选项:




  • 本地数据库

  • 基于服务的数据库



我想要的是一个简单的本地数据库,用于我的项目。



但是,如果我选择本地数据库(精简版),那么在创建我的表并将它们拖动到一个LINQ to SQL类创建器之后,它说:


所选对象使用不受支持的数据提供者。


所以,我不知道为什么创建一个本地数据库会被拖到表对象关系设计器时被认为是不受支持的提供者。



所以,我尝试第二种类型,基于服务的数据库。我布置我的表如何我想要我的基本应用程序,并使我的表。当我拖动这些表时,LINQ-to-SQL设计器工作正常,我继续在我的应用程序中写我的代码以插入和升级数据库条目。



这个第二个基于服务的数据库我的插入和更新工作,只要应用程序正在运行。但是,一旦我关闭它,它恢复到之前的状态。如果我通过服务器资源管理器手动添加数据,它仍然存在,但我所做的任何插入都不保存。



为什么无法创建和使用本地数据库



如果这不是一个选项,那么为什么不是基于服务的数据库(无论是什么),持久超出应用程序关闭? p>

感谢您的时间!






编辑:显然LINQ- To-SQL对象设计器在Compact Edition本地数据库上不工作。它仍然可以做,但你必须使用SqlMetal显然生成dmbl文件。

解决方案

数据库被擦除,一个新的数据库被复制到bin文件夹。因此,尝试链接(使用linq)到bin文件夹中的数据库。请尝试更改您的connectionString。


I'm making a WinForms app in C#. When I go to create my database object, I'm presented with two options:

  • Local Database
  • Service-based Database

All I want is a simple local database to use for my project.

However, if I select "Local Database (Compact Edition)" then after I create my tables and drag them over to a LINQ-To-SQL Class creator it says:

The selected object(s) use an unsupported data provider.

So, I don't know why creating a local database would be considered an unsupported provider when dragging to tables to the Object Relational designer.

So, I try the second type, "Service-based Database". I lay out my tables how I want for my basic application and make my tables. The LINQ-To-SQL Designer works fine when I drag these tables and I proceed to write my code in my app to insert and upate the database entries.

However, with this second "Service-based Database" my inserts and updates work as long as the application is running. However, once I close it it reverts back to what it was before. If I manually add in data via the Server Explorer it persists but any inserts I do don't save.

Why can't I create and use a Local Database with LINQ?

If that isn't an option, then why isn't the "Service-Based Database" (whatever that is), persisting beyond the application closing?

Thanks for your time!


Edit: Apparently the LINQ-To-SQL Object Designer doesn't work on Compact Edition Local Databases. It can still be done, but you have to use SqlMetal apparently to generate the dmbl file.

解决方案

When you compile, the old database gets erased and a new one is copied to the bin folder. Therefore try link (using linq) to the database in the bin folder. Try change your connectionString.

这篇关于LINQ Confusion - 数据库在应用程序关闭后不会继续存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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