5

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Elior
  • 3,178
  • 6
  • 37
  • 67
  • 2
    considering you need an instance of SQL Express, i'd suggest using a flat file (XML etc) rather than a database, making your deployment pre-requisite less and easier to package. – ericosg Apr 07 '13 at 19:23
  • @ericosg thanks, do you have any tutorials for this ? because this is my first time that I'm deploying a project.. – Elior Apr 07 '13 at 19:27
  • it'd start with a google search of "read write xml c#" – ericosg Apr 07 '13 at 19:37
  • @Elior If you need DB you also can consider to use SQL Server Compact instead of SQL Express. To make SQL Server Compact works you can just include right set of dlls. – outcoldman Apr 07 '13 at 19:43
  • @outcoldman thanks for your suggestion but I have to use SQL Express since it's one of my lecturer requirements.. – Elior Apr 07 '13 at 19:45

2 Answers2

5

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!

Community
  • 1
  • 1
Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
  • thanks for your answer :) and no, I'm not aware to this fact.. thanks for the info.. so how it can be done in VS2012 ? – Elior Apr 07 '13 at 20:02
  • 3
    Basically: not. As far a Microsoft is concerned you'd have to learn WIX or buy a commercial installer (the free InstallShield Light Edition sucks). It's amazing. Vote [here](http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/3041773-bring-back-the-basic-setup-and-deployment-project-). – Gert Arnold Apr 07 '13 at 20:07
0

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.
Unheilig
  • 16,196
  • 193
  • 68
  • 98
david
  • 465
  • 5
  • 11