0

My installer has a feature called 'MyDatabase' that shows a dialog to take input 'server, dbname, user, pwd' and creates the specified database.

It works the first time installation. My requirement is to show this dialog everytime the installer is run and this 'MyDatabase' feature is selected. The user may choose to create a new database every time. If the db exists it would display a message and exit.

I managed to show the dialog every time, to take input from the user. But it doesn't install the db except for the first time.

How can I get it to install every time?

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
coder
  • 4,121
  • 14
  • 53
  • 88
  • Is there an accompanying application.exe file in this application? If so install a read-only copy of the database and copy it to a writeable location and initialize it via your application instead of your setup. You can do this any number of times. – Stein Åsmul Apr 28 '15 at 05:34

3 Answers3

1

Let me flesh out the answer a little: When you install a file with MSI it points to it with a component GUID. The MSI file thinks it "owns" the file since you have given it a unique GUID and will happily delete the file on uninstall (this can also happen as part of a major upgrade), even if you have modified the file and it is full of user data. This is a very common design-flaw in many setups.

You can work around this by setting the component permanent as described in this answer: MSI Reference Counting: Two products install the same MSIs. However a better concept is to install only read-only files and use your application itself to initialize user-data (ini files, databases, xml settings files, etc...) by copying the read-only templates to the user profile and / or set them via application internal defaults (defined inside the source code). This decouples the deployment of user-settings and data files from the installer avoiding accidental deletion of user data and allowing you to treat all user data setup from the application with the increased flexibility and control this yields. And you avoid complicating your setup, which is more than complex enough as is described here: What is the benefit and real purpose of program installation?

Many people feel that their setup should uninstall all user data. Don't go there. My take on this, and many with me, is that anything modified by the user is user data and should be left alone in case the user reinstalls the product or if they want to keep their data for import into other applications. You can instead document where data is stored and let people or system administrators clean this out manually. Cleaning out all user data would involve cleaning all user profiles. Though you can use concepts such as ActiveSetup to accomplish this (another ActiveSetup explanation), it is generally more trouble than it is worth and error prone.

For more understanding of the component GUID concept see this answer: Change my component GUID in wix? (recommended read for your use case). Here is a discussion on installsite.net on how to initialize and update userprofile and user data: http://forum.installsite.net/index.php?showtopic=21552

Similar answers (for tracking) - I keep writing the same over and over ;-):

Community
  • 1
  • 1
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
0

As far as the dialog goes, the dialogs in that install will be driven by conditions, and typically you'd have something like a Welcome dialog in the InstallUISequence with a condition that includes "Not Installed", so it shows only the first time. So that must be the kind of thing you have that causes the DB dialog to show only the first time. You'd need to change the condition and the resulting flow of the dialogs (Next, Back, etc) to include this dialog every time you add a feature or whatever the condition really is.

The other half of this is that there must be code somewhere, a custom action, and that is likewise conditioned to run only on a first install with a condition like Not Installed. So you'd find that and give it the same sort of condition as the dialog. You may need to think about what "each time the installer is run" really means? Probably not an uninstall; during repair? When features are removed?

This kind of thing is normally (well at least in my experience) done with an actual app rather than having to go through the install again. You don't get these "when do I run it" issues; the coding and debugging is also much more straightforward.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
0

I figured it's not possible to install the database feature every time the installer is run, since it's bound to the Component GUID. Even though I managed to show the ConnectionStringInputDialog, it doesn't do anything the second time I run the same installer, since it knows that the feature is already installed.

So, I ended up creating a separate C# Windows App, and included that App in the installer. The user can run the App as many times as needed and run the sql scripts (embedded as resource file in the App) as needed.

coder
  • 4,121
  • 14
  • 53
  • 88