简体   繁体   English

WPF + SQL Server Compact调试和部署

[英]WPF + SQL Server Compact Debug and Deploy

I have a WPF project set up to use a local SQL Server Compact database through an ADO.NET Entity Data Model in Visual Studio Express 2012 for Desktop. 我有一个WPF项目设置为通过Visual Studio Express 2012 for Desktop中的ADO.NET实体数据模型使用本地SQL Server Compact数据库。 The project works great, on first run I can load all of the data, manipulate it as I please and come back later with the changed data still in place. 该项目的效果很好,在第一次运行时,我可以加载所有数据,根据需要进行操作,然后在更改后的数据仍然存在的情况下返回。

I noticed while doing a little restructuring to the schema that the data visible to VS was only the very first bits of data that I entered manually when creating the database and the next time I compiled all of the data I had added since was gone! 我注意到,在对架构进行一些重组时,VS可见的数据只是我在创建数据库时手动输入的第一批数据,而下一次我编译自此以来添加的所有数据都消失了!

After some digging, I came to the conclusion that the compiled version of the app was using the SDF file sent to the bin/Debug folder by the file's Content:Copy If Newer build action. 经过一番挖掘后,我得出的结论是,该应用程序的编译版本正在使用通过文件的Content:Copy If Newer构建操作发送到bin / Debug文件夹的SDF文件。 This means that there could be as many as 4 different copies of the database to be worried about: project folder, debug folder, release folder, and the deployed copy on the end user's PC. 这意味着您可能要担心多达4个不同的数据库副本:项目文件夹,调试文件夹,发布文件夹以及最终用户PC上已部署的副本。

I would like to have a single copy of the database on my dev machine that is accessed by both debug and release compiled versions and the database explorer in VS that is installed on the end user's PC by ClickOnce. 我想在我的开发机器上有一个数据库副本,可以通过调试版本和发行版进行访问,也可以通过ClickOnce在最终用户的PC上安装的VS中访问数据库浏览器。 I suppose I could change the connection string to an absolute path during development and hope I can remember to change it back to relative before I publish for deployment. 我想我可以在开发过程中将连接字符串更改为绝对路径,并希望我记得在发布部署之前将其更改回相对。

Finally, I foresee the need to release updates for this application as well and am worried that such an update would erase the end user's data if improperly done. 最后,我预见到也有必要发布此应用程序的更新,并且担心这种更新如果执行不当会抹掉最终用户的数据。 If possible, I would like to be able to only update the schema of the end user's database without touching the data itself whenever I release an update. 如果可能的话,我希望每次发布更新时都只能更新最终用户数据库的架构,而无需接触数据本身。 If this is not possible that is acceptable and I'll just have to make sure I put every structure I can think of into the database before my first deploy. 如果这不可能,那是可以接受的,我只需要确保在我第一次部署之前就将所有可以想到的结构放入数据库中即可。

In summary my questions are the following: 总而言之,我的问题如下:

  1. How to share a single sql compact database between VS, debug, and release? 如何在VS,调试和发布之间共享单个sql紧凑数据库?

  2. How to handle local database during application deployment and updates, with the optional ability to update the database schema without erasing the data? 如何在应用程序部署和更新期间处理本地数据库,并具有可选的更新数据库架构而不删除数据的功能?

I have a similar application and I keep the database file completely separate. 我有一个类似的应用程序,并且将数据库文件完全分开。 Because you may also need to do updates that you don't want the user database overwritten. 因为您可能还需要进行更新,所以您不希望覆盖用户数据库。 I have a process that checks the database schema before the EF connection takes place. 我有一个在EF连接发生之前检查数据库架构的过程。 So when my users install this application it requires they download the database file from my webserver and puts it in a specific location on their computer. 因此,当我的用户安装此应用程序时,它要求他们从我的Web服务器上下载数据库文件并将其放在计算机上的特定位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM