WIX,Dot Net管理的自定义操作,用SQL Server实例,MSI动态填充组合框 [英] WIX, Dot Net managed custom Action, dynamically fill combo box with SQL Server instances, MSI

查看:75
本文介绍了WIX,Dot Net管理的自定义操作,用SQL Server实例,MSI动态填充组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In WIX am in-need of a dot net managed custom code to dynamically populate a combo box with the values of sql server instances in that network.

我尝试过Google,但是没有任何作用

I tried to google but got nothing worked

非常感谢您的帮助.

推荐答案

    [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;       
    }

这篇关于WIX,Dot Net管理的自定义操作,用SQL Server实例,MSI动态填充组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆