How to create a login to a SQL Server instance?

2019-09-03 15:26发布

问题:

I have made a bootstrapper-project with WiX 3.8. As a prerequisite SQL Server Express 2012 is installed, setting "SQLExpress" as name of the new SQL Server instance. Then in the MSI i want to create a new SQL user login. I tried this with the User-element, but it doesn't seem to work. When i take a look to the logins in the SQL Server Management tool, i can't see my new user, but the log from my MSI tells me, that he was created.

Is there something wrong with my version of the User-element or have i to take another way?

<Component Id ="CreateUserAccount"
           Guid="AEE91491-99FA-40A9-AB47-1E9FC2DDEF2A"
           Directory="TARGETDIR">
    <util:User Id ="SQLUser"
               Name="[DBUSER_PROP]"
               Password="[DBPW_PROP]"
               UpdateIfExists="no"
               CreateUser="yes"
               PasswordNeverExpires="yes"
               PasswordExpired="no"
               RemoveOnUninstall="no"
               Domain="[ComputerName]">
    </util:User>
</Component>

回答1:

With the help of Phill Hogland from Windows-installer-xml-wix-toolset i have found the solution. It depends on the language used on the PC. In my case that's german, which means, the group Users cannot be found by the name "Users" but "Benutzer".

Here the correct code:

<util:Group Id="Users"
            Name ="Benutzer"
            Domain="[ComputerName]" />
<Component Id ="CreateUserAccount"
           Guid="AEE91491-99FA-40A9-AB47-1E9FC2DDEF2A"
           Directory="TARGETDIR">
    <util:User Id ="SQLUser"
               Name="[DBUSER_PROP]"
               Password="[DBPW_PROP]"
               UpdateIfExists="no"
               CreateUser="yes"
               PasswordNeverExpires="yes"
               PasswordExpired="no"
               RemoveOnUninstall="no">
        <util:GroupRef Id ="Users" />
    </util:User>
</Component>

Further You can replace the hardcoded name by a bundle-variable. Then You will be independent from the OS language.