-1

I recently developed a winform application with c# and SQL Server 2008 data access. I want to create an "InstallShield express" setup file for it (I don't want to use ClickOnce or Setup And Deployment witch is available in VS). I want to create a db or attach it to SQL server instance after installing SQL Server Express 2008 SP3 (not local db). What is the best way to do this?

Mahmood Jenami
  • 421
  • 1
  • 7
  • 20

1 Answers1

0

Your question is quite vague as you do not explain what kind of “app”, “setup file” or “db” you are using, nor how you “attach it to sql”. In the future, please include these details. However, I can give a general answer.

  1. Create a seed database, that contains the starting data for your application, in your source project.
  2. Add the seed database file to your project/solution file and set its Build Action to “Content”.
  3. Ensure your installer includes project content in the deployment folder (the application folder for WinForms apps).
  4. To open the seed database from your app, use a connection string like Data Source=|DataDirectory|seed.sdf. Do not try to search for your seed file or to set DataDirectory yourself; the installer will set DataDirectory to the directory your content was installed to.
  5. Do not try to write to DataDirectory; it may not be writable by the user who installed it. Repairing the app will overwrite DataDirectory, destroying anything you saved there, as well.
  6. If you need to save data in the database, copy |DataDirectory|seed.sdf to Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), then read and write all data to the copy.

For more information, read my answer to a poster who wrote to |DataDirectory| and therefore kept destroying his user's data.

Community
  • 1
  • 1
Dour High Arch
  • 21,513
  • 29
  • 75
  • 90