I have an installer created using Wix. I'd like to be able to specify the location where the sql server is installed. One solution I can think of is to put a placeholder in the CreateDatabase script and in the run time just replace the placeholder with the actual path that user specified.
I am wondering if there is any better way to do this? Does Wix provide anything I can use of?
Thanks,
You can take advantage of standard WiX SQL extension. For instance, SqlString element provides an option to specify a SQL query to execute at install time. SqlDatabase element gives an out-of-the-box option to create SQL database. Both accept Windows Installer properties for @SQL and @Server attributes respectively. This means that you can get user input, save it to the property and use that property in Sql elements.
I end up solving this problem by using a dynamical SQL. For anyone looking for solution, please check the accepted answer for the following question:
SQL Server: use parameter in CREATE DATABASE
You can't get this for free from WiX.
Using SqlString, some parameters and as you noted direct use of CREATE DATABASE. You'll need:
If you are expecting to use SQL auth you'll of course also need to pass in DB_USER/DB_PASS
I would strongly suggest writing your own custom actions to verify the parameters.
Expanding on Yan's answer, there's a very simple syntax if you use the Sql extension - You need both the MDF and LDF (Data + Log files) included for your SQL database, but then attach them by referencing the same filename.
The following assumes a sql express server will be installed locally under the localhost\sqlexpress instance
I've omitted authentication from this example for brevity, but you can also specify a Sql user to use for the command using the User element, and referencing the User element's Id within the SqlDatabase attribute.