I'm trying to create a database and run some SQL scripts from my Windows installer, which works fine as long as I hard-code the server name. If I try to get the server name from the registry, the installer will fail. In this case, I have the 32-bit SQL Server installed on a 64-bit OS, so I'm using the following registry key:
<Property Id="SQL_SERVER_INSTANCE">
<RegistrySearch Id="rs_ServerInstance"
Type="directory"
Root="HKLM"
Key="Software\Wow6432Node\Microsoft\Microsoft SQL Server\Instance Names\SQL"
Name="SQLEXPRESS" />
</Property>
Then I plug this property into my database setup:
<sql:SqlDatabase Id="NewSQLDB" Database="wix_test_DB" User="Users" Server="[SQL_SERVER_INSTANCE]"
CreateOnInstall="yes" DropOnUninstall="yes" ContinueOnError="no" >
<sql:SqlScript ..."/>
</sql:SqlDatabase>
And it will fail. I've checked the registry and the only Name/Value pair there is "SQLEXPRESS" and the value is not a server instance. The server itself is called "SQLEXPRESS", but if it's stored as the Name, then I need to know it in advance to be able to search for it, defeating the purpose of attaining it in the first place.
I understand why this code doesn't work, but I don't know how I can get the server name. I've read that you can use [SQLSERVER] as the SqlDatabase@Server to get the default server, but the installer still failed when I tried this.
Is there a way to get the server name (not necessarily using the registry)?