0

I have a Windows Form application that uses 2 databases and there are tables that are used as flags and references. What is usually done to deploy these databases with tables filled with data by default? I was thinking of using Script database as CREATE to then put all of those generated scripts into one SQL file and just have my application execute it but, it only creates the database or the tables but not the data needed.

EDIT

Also, if my application also is going to have a Windows Service, do I have to separate the setup for that or can I include that with my client application setup?

J.P Masangcay
  • 759
  • 2
  • 10
  • 28
  • How are you deploying it? Command-line? From Visual Studio? VS database projects have a rather nice Post Deploy Scripts with Build Action **PostDeploy**. I use them to set look-up tables/enums that sort of thing in a schema-first DB –  Dec 14 '15 at 05:44
  • @Micky I am planning to have my client application deployed with Clickonce or something similar that anyone here can recommend. My problem is my database if I need to have it created from my client app or if there is another easier way. – J.P Masangcay Dec 14 '15 at 05:49
  • If you are using EntityFramework Migrations you can use the `Configuration.Seed` method of a particular `Migration` with `DbSet.AddOrUpdate`. If you are using something other than EntityFramework searching for the term "seed" should be helpful for a more general solution. – Bradley Uffner Dec 14 '15 at 05:58
  • @BradleyUffner I am currently using EF Database first. As far as I have checked, migrations are for code-first? – J.P Masangcay Dec 14 '15 at 06:10

1 Answers1

0

What is usually done to deploy these databases with tables filled with data by default?

  • As you have already mentioned, One of the option is to include the scripts to create the database schema and then insert the necessary data required. and during the deployment of your application you could execute these scripts. SMO(SQL Server Management Object) should be the best option to execute scripts.

  • Second option would be to use LocalDB, it's a lightweight version of SQL Express. you could add the database file to your installer project and copy to user machine along with other files. When the application runs you could refer to this DB file in the connection string using AttachDbFileName property.

if my application also is going to have a Windows Service, do I have to separate the setup for that?

Well, technically you could use a single setup to deploy your client application and install windows service but to install the service you will have to write extra code. Unless you have a requirement to use single MSI to deploy both i would advice you to create a separate setup to deploy your service.

Community
  • 1
  • 1
Kurubaran
  • 8,696
  • 5
  • 43
  • 65
  • So, for my database and tables, that's the only way to go? – J.P Masangcay Dec 14 '15 at 06:20
  • @J.PMasangcay Those are easy options, out of these I would pick using script files, once the app is rolled out to production you might need to keep a separate file with delta scripts. new user would get all the changes other would only get delta. its relatively easy handle these with scripts rather than attaching DB file to installer. – Kurubaran Dec 14 '15 at 06:27