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?
Asked
Active
Viewed 1,058 times
1 Answers
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.
- Create a seed database, that contains the starting data for your application, in your source project.
- Add the seed database file to your project/solution file and set its Build Action to “Content”.
- Ensure your installer includes project content in the deployment folder (the application folder for WinForms apps).
- 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 setDataDirectory
yourself; the installer will setDataDirectory
to the directory your content was installed to. - Do not try to write to
DataDirectory
; it may not be writable by the user who installed it. Repairing the app will overwriteDataDirectory
, destroying anything you saved there, as well. - If you need to save data in the database, copy
|DataDirectory|seed.sdf
toEnvironment.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
-
Thanks for your answer. but let me edit my question, to be more obvious. – Mahmood Jenami Sep 01 '15 at 09:35