簡體   English   中英

修改數據庫時,WiX Toolset自定義操作失敗

[英]WiX Toolset Custom Action Fails When Modifying Database

我一直在瘋狂地試圖弄清楚為什么視圖沒有更新。 從網上看到的所有帖子中,我認為我做得對,但是我一直收到Null錯誤。 如果我嘗試使用session.Database.FilePath以這種方式加載數據庫,則說FilePath為null。 視圖本身正在返回虛擬行,因此數據庫位於其中。 真是奇怪

以下是物業

<Property Id="IIS_SITE" />

二進制和自定義動作

<CustomAction Id="UpdateComboBoxes" DllEntry="UpdateComboBoxes" BinaryKey="UpdateComboBoxes" Execute="immediate" Return="check" />
<Binary Id="UpdateComboBoxes" SourceFile="..\ProjectName.CustomActions\bin\Release\ProjectName.CustomActions.CA.dll"/>

安裝UI序列

<InstallUISequence>
  <Custom Action="UpdateComboBoxes" Before="CostFinalize"></Custom>
</InstallUISequence>

控制

   <Control Id="IisSite" Type="ComboBox" Sorted="yes" ComboList="yes" Property="IIS_SITE" X="45" Y="85" Width="220" Height="18" >
      <ComboBox Property="IIS_SITE" >
        <ListItem Text="Dummy" Value="Dummy"/>
      </ComboBox>
    </Control>

自定義動作

     [CustomAction]
    public static ActionResult UpdateComboBoxes(Session session)
    {
        session.Log("Begin Custom Action UpdateComboBoxes");
        try
        {
            session.Log(string.Format("Database Location is: {0}", session.Database.FilePath));
            var database = session.Database;
                using (var view = database.OpenView("SELECT * FROM ComboBox WHERE Property = 'IIS_SITE'"))
                {

                    view.Execute();
                    session.Log("Executed view");

                    var isReadOnly = database.IsReadOnly;

                    session.Log(string.Format("Database is read only: {0}", isReadOnly));
                    session.Log(string.Format("# of rows in ComboBox Table: {0}",
                        view.Database.CountRows("ComboBox", "Property = 'IIS_SITE'")));

                    using (var serverManager = new ServerManager())
                    {
                        session.Log("Accessed Server Manager");
                        var index = 1;
                        var rowIndex = 1;
                        session.Log(string.Format("Going through {0} sites", serverManager.Sites.Count));
                        foreach (var site in serverManager.Sites)
                        {
                            if (!string.IsNullOrEmpty(site.Name))
                            {
                                session.Log(string.Format("Site # {0} {1}", index, site.Name));
                                var record = session.Database.CreateRecord(4);
                                //Property
                                record.SetString(1, "IIS_SITE");
                                //Order
                                record.SetString(2, rowIndex.ToString());
                                //Value
                                record.SetString(3, site.Name);
                                //Text
                                record.SetString(4, site.Name);

                                session.Log(string.Format("Modifying the view for site # {0}", index));
                                view.Modify(ViewModifyMode.InsertTemporary, record);
                            }
                            session.Log("Incrementing index");
                            index++;
                            rowIndex++;
                        }
                    }

                    session.Log("Closing the view");
                }
        }
        catch (Exception e)
        {

            session.Log(string.Format("ERROR in UpdateComboBoxes: {0}", e.Message));
            session.Log(e.StackTrace);
            var inner = e.InnerException;
            if(inner != null)
            {
                session.Log(string.Format("{0}{1}", "\t", inner.Message));
                session.Log(string.Format("{0}{1}", "\t", inner.StackTrace));
            }
            while ((inner = inner.InnerException) != null)
            {
                session.Log(string.Format("{0}{1}", "\t", inner.Message));
                session.Log(string.Format("{0}{1}", "\t", inner.StackTrace));
            }
            return ActionResult.Failure;
        }
        return ActionResult.Success;
    }

我得到的錯誤:

MSI(c)(B0!F4)[14:46:40:369]:注意:1:2259 2:3:3:4:
UpdateComboBoxes中的錯誤:函數在執行期間失敗。 VideoQuestionInstaller.CustomActions.CustomActions.UpdateComboBoxes(Session session)上的Microsoft.Deployment.WindowsInstaller.View.Modify(ViewModifyMode模式,記錄記錄)在自定義操作上引發的異常:System.Reflection.TargetInvocationException:調用。 ---> System.NullReferenceException:對象引用未設置為對象的實例。 在VideoQuestionInstaller.CustomActions.CustomActions.UpdateComboBoxes(Session session)-內部異常堆棧跟蹤的結尾--在System.RuntimeMethodHandle.InvokeMethod(Object target,Object arguments,Signature sig,Boolean構造函數)在System.Reflection.RuntimeMethodInfo。 Microsoft.Deployment.WindowsInstaller.CustomActionProxy.InvokeCustomAction(Int32 sessionHandle,String。 entryPoint,IntPtr remotingDelegatePtr)

我查了一下,錯誤2259表示數據庫更新失敗,這很明顯,因為錯誤之前的最后一個日志是:修改站點#1的視圖。

有人對我做錯了什么有什么想法,為什么ComboBox數據庫沒有更新?

提前致謝!

沒關系,我知道了問題所在。 這是我的解決方法:

我添加了另一個隱藏的控件,以便創建組合框表,而不必將假值放入要使用的實際組合框中。

    <Property Id="HIDDEN_IIS_SITE" />

    <Control Id="DummyComboBox" Hidden="yes" Type="ComboBox" Sorted="yes" ComboList="yes" Property="HIDDEN_IIS_SITE" X="45" Y="85" Width="220" Height="18" >
      <ComboBox Property="HIDDEN_IIS_SITE" >
        <ListItem Text="Dummy" Value="Dummy"/>
      </ComboBox>
    </Control>

然后,我更改了自定義操作,以使其獲得現有行的實際數量,然后在添加記錄時將其添加到該行中,以便使用訂單的正確編號

    [CustomAction]
    public static ActionResult UpdateComboBoxes(Session session)
    {
        session.Log("Begin Custom Action UpdateComboBoxes");
        try
        {
            var database = session.Database;
                using (var view = database.OpenView("SELECT * FROM ComboBox WHERE Property = 'IIS_SITE'"))
                {

                    view.Execute();
                    session.Log("Executed view");

                    var index = view.Database.CountRows("ComboBox", "Property = 'IIS_SITE'");

                    using (var serverManager = new ServerManager())
                    {
                        foreach (var site in serverManager.Sites)
                        {
                            if (!string.IsNullOrEmpty(site.Name))
                            {
                                var record = session.Database.CreateRecord(4);
                                //Property
                                record.SetString(1, "IIS_SITE");
                                //Order
                                record.SetString(2, (++index).ToString());
                                //Value
                                record.SetString(3, site.Name);
                                //Text
                                record.SetString(4, site.Name);

                                view.InsertTemporary(record);

                                session.Log("Inserted new record");
                            }
                        }
                    }
                    session.Log("Closing the view");
                }
        }
        catch (Exception e)
        {

            session.Log(string.Format("ERROR in UpdateComboBoxes: {0}", e.Message));
            session.Log(e.StackTrace);
            var inner = e.InnerException;
            if(inner != null)
            {
                session.Log(string.Format("{0}{1}", "\t", inner.Message));
                session.Log(string.Format("{0}{1}", "\t", inner.StackTrace));
            }
            while (inner != null && (inner = inner.InnerException) != null)
            {
                session.Log(string.Format("{0}{1}", "\t", inner.Message));
                session.Log(string.Format("{0}{1}", "\t", inner.StackTrace));
            }
            return ActionResult.Failure;
        }
        return ActionResult.Success;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM