Create installer for winForms with local DB

2020-03-24 08:25发布

I have a Winforms application (checkers game) which have a local DB (using SQL Server Express) to save the registered players and their scores..

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?

2条回答
虎瘦雄心在
2楼-- · 2020-03-24 08:53

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.

enter image description here

Side note: Are you aware of the fact that in VS2012 the MSI deployment project template is deprecated?

Addition: And it's back in VS 2013!

查看更多
干净又极端
3楼-- · 2020-03-24 09:02

This is my workaround in wpf. I think solution is the same in Winform:

  1. Make your mdf file "content" by right clicking on that and select properties. 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).

Connection String Must be the same

  1. Right click in your setup project and Add->Project output-> then select content files.
查看更多
登录 后发表回答