How to Filter Specific Instances of Servers on the SQLBrowse Dialog During Basic MSI Installations

When you add connections in the SQL Scripts view in InstallShield, your installation displays the SQLLogin dialog at run time. When end users click the Browse button next to the target server field on the dialog, the SQLBrowse dialog opens; this dialog provides a list of available servers on local and network machines. In some cases, you want to hide some specific instances from the list of servers. For Basic MSI projects, you can accomplish this by writing a custom action that removes items from the IS_SQLSERVER_LIST ListBox control. This VBScript example illustrates removing all of the named instances from the list starting with SQLEXPRESS.

Const msiViewModifyDelete = 6

Const IDOK = 1

‘ open and execute a view to the ListBox table

Set viewlist = Database.OpenView(“SELECT * FROM `ListBox` WHERE `Property`=’IS_SQLSERVER_LIST'”)

viewlist.Execute

Set reclist = viewlist.Fetch

While Not (reclist Is Nothing)

    If InStr(reclist.StringData(4), “SQLEXPRESS”) <> 0) Then

         ‘ delete the ListBox record

         viewlist.Modify msiViewModifyDelete, reclist                                                                                                        

    End If

    ‘ fetch the next ListBox record

    Set reclist = viewlist.Fetch

Wend

‘ clean up

viewlist.Close

You need to execute this code by a VBScript custom action after the list of servers is created and before the SQLBrowse dialog is displayed by following steps below.

  1. In InstallShield, open a Basic MSI project that includes a SQL connection that you configured through the SQL Scripts view.
  2. Create a custom action that removes the named instances from the list of servers:
    • In the View List under Behavior and Logic, click Custom Actions and Sequences.
    • Right-click the Custom Actions explorer, point to New VBScript, and then click Store in custom action.
    • Name the new custom action RemoveSqlExpressInstances.
    • On the Common tab, keep all of the default settings.

Hidblog

 

  • On the Script tab, enter the aforementioned sample VBScript.

3.  Edit the SQLLogin dialog to call the custom action when an end user clicks the SQLLogin dialog’s Browse button:

  • In the View List under User Interface, click Dialogs.
  • In the Dialogs explorer, under the All Dialogs node, expand the SQLLogin dialog node.
  • Under the SQLLogin dialog node, click the Behavior node.
  • In the SQLLogin Dialog Behavior grid, click the BtnSQLBrowse PushButton control.
  • In the BtnSQLBrowse PushButton grid, click the Click here to add a new item row, and enter the following values:
  • Event:          DoAction
  • Argument: RemoveSqlExpressInstances
  • Condition:  1
  • Right-click the event that you added in the previous step, and click Move up to sequence the event immediately after the event calling the  ISSQLServerList action.

Hidor2

4.  Build your installation.

If anyone has any comments or questions, please let me know!

 

Tags: ,

4 comments on “How to Filter Specific Instances of Servers on the SQLBrowse Dialog During Basic MSI Installations

  1. Hidenori Yamanishi on

    Here is a sample InstallScript code that does the same task. If it still crashes, I would suggest debugging the code to find out where the problem comes from.

    export prototype RemoveSqlExpressInstances(HWND);

    function RemoveSqlExpressInstances(hInstall)
    HWND hDB, hViewlist, hRecordlist;
    STRING svListData;
    NUMBER nBuffer;
    begin

    hDB = MsiGetActiveDatabase(hInstall);

    // open view into ListBox table
    MsiDatabaseOpenView(hDB,
    “SELECT * FROM `ListBox` WHERE `Property`=’IS_SQLSERVER_LIST'”,
    hViewlist);
    MsiViewExecute(hViewlist, NULL);

    // remove instance names starting with SQLEXPRESS
    while (MsiViewFetch(hViewlist, hRecordlist) != ERROR_NO_MORE_ITEMS)

    nBuffer = 256; // set size buffer
    MsiRecordGetString(hRecordlist, 4, svListData, nBuffer);

    if(StrFind(svListData, “SQLEXPRESS”) >= 0) then
    MsiViewModify(hViewlist, MSIMODIFY_DELETE, hRecordlist);
    endif;

    endwhile;

    MsiViewClose(hViewlist);

    end;

    Create a new InstallScript file:
    • In the View List under Behavior and Logic, click InstallScript.
    • Right-click on the Files explorer, and then select the New Script File.
    • Enter the aforementioned sample InstallScript.

    Create an InstallScript custom action:
    • In the View List under Behavior and Logic, click Custom Actions and Sequences.
    • Right-click the Custom Actions explorer, and then click New InstallScript
    • Name the new custom action RemoveSqlExpressInstances.
    • On the Common tab, type or select the RemoveSqlExpressInstances function for the Function Name setting.
    • Keep all of the other default settings.

    Thanks!
    Hidenori

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *