加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

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

发布时间:2020-12-12 08:45:03 所属栏目:MsSql教程 来源:网络整理
导读:在WIX中,需要一个点网络管理的自定义代码,以动态填充组合框中该网络中sql服务器实例的值. 我试图google,但没有任何工作 任何帮助是极大的赞赏. 解决方法 [CustomAction] public static ActionResult FillServerInstances(Session xiSession) { xiSession.Log(
在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;       
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读