9

How do I detect if Sql Server Express is installed and running on a machine in a WiX installer?

I want to check before installing my application and if it's not installed and running, to inform the user that it has to be installed first before installing my application.

Krzysztof Kozmic
  • 27,267
  • 12
  • 73
  • 115

3 Answers3

11

Ok, I found by trial and error option that works:

<Property Id="SQLSERVER">
  <RegistrySearch Id="SQLServer" Root="HKLM" Key="SOFTWARE\Microsoft\Microsoft Sql Server" Type="raw" Name="InstalledInstances"/>
</Property>

I define a registry search, and then check its value:

<Condition Message="You don't have SQL Server installed.">
  <![CDATA[SQLSERVER >< SQLEXPRESS]]>
</Condition>
Krzysztof Kozmic
  • 27,267
  • 12
  • 73
  • 115
  • Perfect, just hit the same issue. At first I thought it wouldn't work for the case of having both SQL Server Standard & Express installed, but then noticed the "><" which after a bit of digging I discovered means left contains right, oddly I couldn't find mention of that conditional expression operator mentioned in the Wix docs, but did find it here: http://www.tramontana.co.hu/wix/lesson6.php. – Bittercoder Nov 11 '09 at 23:26
  • You wont find the InstalledInstance value on 64Bits Windows version. – jmayor Aug 23 '10 at 18:00
6

I tried Krzysztof's solution (above) - but on some machines when using this approach it wasn't correctly detecting when they did not have Sql Express installed.

It looked to be caused by mishandling of the REG_MULTI_SZ InstalledInstances registry value?

As I was checking to see if I needed to stop/restart the Sql Server Express service in the installer, I decided to just check against that instead - so here's my alternative, where I just check for the service instead:

<Property Id="SQLEXPRESSINSTALLED" >
  <RegistrySearch Id="IsSqlExpressServiceInstalled" Root="HKLM" Key="SYSTEM\CurrentControlSet\services\MSSQL$SQLEXPRESS" Name="Description" Type="raw" Win64="no"/>
</Property>      

<Condition Message="Express Not Installed">SQLEXPRESSINSTALLED</Condition>

<Condition Message="Express Installed">NOT SQLEXPRESSINSTALLED</Condition>

Bit of a hack, but seems to work well enough for our customers (were using the conditions within components, rather then the example Launch conditions shown above)

Bittercoder
  • 11,753
  • 10
  • 58
  • 76
1

The accepted answer above was always passing the condition for me. I got it working using:

<Property Id="SQLSERVER_INSTANCE">
  <RegistrySearch Id="SQLServerRegSearch" Root="HKLM" Key="SOFTWARE\Microsoft\Microsoft Sql Server\Instance Names\SQL" Type="raw" Name="SQLEXPRESS"/>
</Property>
<Condition Message="You don't have SQL Server installed.">
  <![CDATA[SQLSERVER_INSTANCE]]>
</Condition>
patrickbadley
  • 2,510
  • 2
  • 29
  • 30
  • All of the answers seem to make the same assumption - that the SQL Express instance is installed with an instance name of `SQLEXPRESS`. Whilst that *is* the default, it is changable. – Damien_The_Unbeliever Jul 11 '12 at 13:15
  • That is true, so in place of SQLEXPRESS you should check for the instance name that you need, whatever it may be. – patrickbadley Jul 16 '12 at 13:18