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

前端之家收集整理的这篇文章主要介绍了安装程序 – WIX,Dot Net管理的自定义Action,动态填充组合框与SQL Server实例MSI前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在WIX中,需要一个点网络管理的自定义代码,以动态填充组合框中该网络中sql服务器实例的值.

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

任何帮助是极大的赞赏.

解决方法

  1. [CustomAction]
  2. public static ActionResult FillServerInstances(Session xiSession)
  3. {
  4. xiSession.Log("Begin CustomAction");
  5.  
  6. xiSession.Log("opening view");
  7. View lView = xiSession.Database.OpenView("DELETE FROM ComboBox WHERE ComboBox.Property='DBSRVR'");
  8. lView.Execute();
  9.  
  10. lView = xiSession.Database.OpenView("SELECT * FROM ComboBox");
  11. lView.Execute();
  12.  
  13. int Index = 1;
  14. bool flag = false;
  15. try
  16. {
  17. foreach (DataRow dr in Microsoft.sqlServer.Management.Smo.SmoApplication.EnumAvailablesqlServers(false).Rows)
  18. {
  19. String InstanceName = dr["Name"].ToString();
  20.  
  21. if (InstanceName.Equals(xiSession["ComputerName"] + @"\" + xiSession["sqlINSTANCENAME"],StringComparison.InvariantCultureIgnoreCase))
  22. { flag = true; }
  23.  
  24. Record lRecord = xiSession.Database.CreateRecord(4);
  25. xiSession.Log("Setting record details");
  26. lRecord.SetString(1,"DBSRVR");
  27. lRecord.SetInteger(2,Index);
  28. lRecord.SetString(3,InstanceName);
  29. lRecord.SetString(4,InstanceName);
  30.  
  31. xiSession.Log("Adding record");
  32. lView.Modify(ViewModifyMode.InsertTemporary,lRecord);
  33.  
  34. ++Index;
  35. }
  36. }
  37. catch (Exception ex)
  38. {
  39. logException(xiSession,ex);
  40. }
  41. if (flag)
  42. {
  43. xiSession["DBSRVR"] = xiSession["ComputerName"].ToString() + @"\" + xiSession["sqlINSTANCENAME"].ToString();
  44. }
  45.  
  46. lView.Close();
  47.  
  48. xiSession.Log("Closing view");
  49. lView.Close();
  50. return ActionResult.Success;
  51. }

猜你在找的MsSQL相关文章