简体   繁体   English

使用本地DB为winForms创建安装程序

[英]Create installer for winForms with local DB

I have a Winforms application (checkers game) which have a local DB (using SQL Server Express) to save the registered players and their scores.. 我有一个Winforms应用程序(跳棋游戏),它有一个本地数据库(使用SQL Server Express)来保存注册的玩家及其分数。

I'm trying to create an installer for this app by this tutorial 我正在尝试通过本教程为此应用程序创建安装程序

Everything is fine, but when I'm trying to add the players I'm getting a SQL error that says the database wasn't found.. so how can I add the local DB ( .mdf file) to the installer? 一切都很好,但是当我尝试添加播放器时,我收到的SQL错误表明找不到数据库..那么如何将本地数据库( .mdf文件)添加到安装程序?

Provided that the conditions to use local DB at the client machine are OK (see LocalDB deployment on client PC ), in the deployment project you can just add the database files to the application folder (Choose File System Editor in the solution explorer when the deployment project is selected. 如果在客户端计算机上使用本地数据库的条件正常(请参阅客户端PC上的LocalDB部署 ),则在部署项目中,您只需将数据库文件添加到应用程序文件夹(在部署时选择解决方案资源管理器中的文件系统编辑器)项目被选中。

在此输入图像描述

Side note: Are you aware of the fact that in VS2012 the MSI deployment project template is deprecated? 附注:您是否意识到在VS2012中不推荐使用MSI部署项目模板?

Addition: And it's back in VS 2013! 另外:它又回到VS 2013!

This is my workaround in wpf . 这是我在wpf中的解决方法 I think solution is the same in Winform: 我认为Winform中的解决方案是相同的:

  1. Make your mdf file " content " by right clicking on that and select properties. 右键单击mdf文件并选择属性,使其成为“ 内容 ”。 In " build action " menu select " content ". 在“ 构建操作 ”菜单中选择“ 内容 ”。 And in copy to output directory select copy always 并且在复制到输出目录时总是选择复制

  2. In Solution explorer go to Properties/Settings.Settings and put connection strings in a field (notice that name of that must be the same as it is in your App.config (eg in wpf) like picture below it will create). Solution explorer中,转到Properties / Settings.Settings并将连接字符串放在一个字段中(注意它的名称必须它在App.config中的名称 相同 (例如在wpf中),如下图所示,它将创建)。

连接字符串必须相同

  1. Right click in your setup project and Add->Project output-> then select content files . 右键单击您的安装项目添加 - >项目输出 - >然后选择内容文件

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

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