test MS SQL SERVER connection?

Comments

1 comment

  • Avatar
    juanjo

    InstallBuilder do not have a built-in method to validate the connection but you could call the client binary from a <runProgram> action:

                          <actionGroup>
                                <abortOnError>0</abortOnError>
                                <showMessageOnError>0</showMessageOnError>
                                <actionList>
                                    <setInstallerVariable name="connection_validated" value="0" />
                                    <runProgram>
                                        <program>${mssql_client}</program>
                                        <programArguments>-U${mssql_root_user} -P${mssql_root_password} -S${mssql_dsn} -Q "exit"</programArguments>
                                    </runProgram>
                                    <setInstallerVariable name="connection_validated" value="1" />
                                </actionList>
                            </actionGroup>
                            <throwError>
                                <text>Unable to connect to database ${mssql_dsn} as a ${mssql_root_user} database user. Please check your configuration.</text>
                                <ruleList>
                                    <isFalse value="${connection_validated}" />
                                </ruleList>
                            </throwError>
    

    Where mssql_dsn would be ${env(COMPUTERNAME)}\\${mssql_instance} and the mssql_instance can be the result of a choiceParameter, populated from the registry:

    <registryFind>
      <findAll>1</findAll>
      <keyPattern>*</keyPattern>
      <namePattern>*</namePattern>
      <rootKey>HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL</rootKey>
      <searchDepth>1</searchDepth>
      <variable>mssql_info</variable>
    </registryFind>
    <foreach>
      <values>${mssql_info}</values>
      <variables>key name value</variables>
      <actionList>
         <addChoiceOptionsFromText>
           <name>mssql_instance</name>
           <text>${value}=${value}</text>
         </addChoiceOptionsFromText>
         </actionList>
      </foreach>
    

Please sign in to leave a comment.