安装程序 – WIX,Dot Net管理的自定义Action,动态填充组合框与SQL Server实例MSI

在WIX中,需要一个点网络管理的自定义代码,以动态填充组合框中该网络中sql服务器实例的值.

我试图google,但没有任何工作

任何帮助是极大的赞赏.

解决方法

[CustomAction]   
    public static ActionResult FillServerInstances(Session xiSession)
    {         
        xiSession.Log("Begin CustomAction");

        xiSession.Log("opening view");
        View lView = xiSession.Database.OpenView("DELETE FROM ComboBox WHERE ComboBox.Property='DBSRVR'");
        lView.Execute();

        lView = xiSession.Database.OpenView("SELECT * FROM ComboBox");
        lView.Execute();

        int Index = 1;
        bool flag = false;
        try
        {
            foreach (DaTarow dr in Microsoft.sqlServer.Management.Smo.SmoApplication.EnumAvailablesqlServers(false).Rows)
            {
                String InstanceName = dr["Name"].ToString();

                if (InstanceName.Equals(xiSession["ComputerName"] + @"\" + xiSession["sqlINSTANCENAME"],StringComparison.InvariantCultureIgnoreCase))
                { flag = true; }

                Record lRecord = xiSession.Database.CreateRecord(4);
                xiSession.Log("Setting record details");
                lRecord.SetString(1,"DBSRVR");
                lRecord.SetInteger(2,Index);
                lRecord.SetString(3,InstanceName);
                lRecord.SetString(4,InstanceName);

                xiSession.Log("Adding record");
                lView.Modify(ViewModifyMode.InsertTemporary,lRecord);

                ++Index;
            }
        }
        catch (Exception ex)
        {
            logException(xiSession,ex);              
        }
        if (flag)
        {
            xiSession["DBSRVR"] = xiSession["ComputerName"].ToString() + @"\" + xiSession["sqlINSTANCENAME"].ToString();
        }

        lView.Close();

        xiSession.Log("Closing view");
        lView.Close();
        return ActionResult.Success;       
    }

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...