I've got a windows service that creates a named sql localdb instance during installation. I execute commands as the local system account during installation and can create, info query, and start the instance. I'm creating it using a wix custom action run as the localsystem account, it kicks off without a hitch:
<!-- Custom action for creating a named localdb instance -->
<CustomAction Id="CA_SetPropertiesCreateLocalDbInstance" Property="CA_CreateLocalDbInstance" Value="InstanceName=MyLocalDbInstance" />
<CustomAction Id="CA_CreateLocalDbInstance" BinaryKey="BIN_CustomActions" DllEntry="CreateLocalDbInstance" Execute="deferred" Impersonate="no" Return="check" HideTarget="no" />
<!-- Schedule the Custom Actions -->
<InstallExecuteSequence>
<Custom Action="CA_SetPropertiesCreateLocalDbInstance" Before="CA_CreateLocalDbInstance">NOT Installed</Custom>
<Custom Action="CA_CreateLocalDbInstance" Before="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>
The logs from that custom action running during install:
Executing command 'sqllocaldb c MyLocalDbInstance'
command output>> LocalDB instance "MyLocalDbInstance" created with version 14.0.3162.1.
command exit code>> 0
Executing command 'sqllocaldb s MyLocalDbInstance'
command output>> LocalDB instance "MyLocalDbInstance" started.
command exit code>> 0
Executing command 'sqllocaldb i MyLocalDbInstance'
command output>> Name: MyLocalDbInstance
command output>> Version: 14.0.3162.1
command output>> Shared name:
command output>> Owner: NT AUTHORITY\SYSTEM
command output>> Auto-create: No
command output>> State: Running
command output>> Last start time: 8/8/2019 11:40:23 PM
command output>> Instance pipe name: np:\\.\pipe\LOCALDB#3FB77699\tsql\query
command exit code>> 0
However, when I try and access the localdb instance during the application runtime, I get the error error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.
If I use psexec.exe (MSFT tool for powershell) to run sqllocaldb queries as the localsystem account, I can see the localdb instance I created:
PS C:\WINDOWS\system32> whoami
nt authority\system
PS C:\WINDOWS\system32> sqllocaldb i
MSSQLLocalDB
MyLocalDbInstance
I can access info on the default instance no problem, but trying to query the instance created results in an error:
PS C:\WINDOWS\system32> sqllocaldb i MyLocalDbInstance
Printing of LocalDB instance "MyLocalDbInstance" information failed because of the following error:
LocalDB instance "MyLocalDbInstance" doesn't exist!
Interestingly, if I run "sqllocaldb c MyLocalDbInstance" again from the localsystem powershell instance, it creates a new instance. Subsequent executions of the "sqllocaldb c MyLocalDbInstance" command simply overwrite the newly created one:
PS C:\WINDOWS\system32> sqllocaldb c MyLocalDbInstance
LocalDB instance "MyLocalDbInstance" created with version 14.0.3162.1.
PS C:\WINDOWS\system32> sqllocaldb c MyLocalDbInstance
LocalDB instance "MyLocalDbInstance" created with version 14.0.3162.1.
PS C:\WINDOWS\system32> sqllocaldb i
MSSQLLocalDB
MyLocalDbInstance
MyLocalDbInstance
I'm pretty stumped, and am probably missing knowledge of one of the following to trace the issue:
-weird windows-user compartmentalization things preventing access
-internal complexities in sqllocaldb
-artefactual interactions with psexec.exe masking the real problem
My next debugging step is probably to make the instance "Shared" during installation, but that's undesirable for security reasons.
I can try and put up a dummy project with a dummy installer if anyone really wants to dig in.