Problem with modifying an MSI database property

牧云@^-^@ 提交于 2021-02-17 05:13:51

问题


I need to modify the UpgradeCode property of the Upgrade MSI table via C#. This code works ok with other tables' properties, but throws an error when I'm trying to modify these.

using (var database = new Database(TEMPDATABASE, DatabaseOpenMode.Direct))        
{
    string upgradeCode = Guid.NewGuid().ToString("B").ToUpper();
    database.Execute("Update `Upgrade` Set `Upgrade`.`UpgradeCode` = '{0}'", upgradeCode);
}

The error is:

Microsoft.Deployment.WindowsInstaller.InstallerException: 'Function failed during execution.'


回答1:


I got curious and pillaged github.com - and it giveth the following: Full project - just download it as a whole.

The actual code was (some unicode line feed issues in the file on github.com, I have fixed them up here):

public static void UpdateUpgradeTable(this Database db, Guid upgradeCode)
{
    using (View view = db.OpenView("SELECT * FROM `Upgrade`", new object[0]))
    {
        view.Execute();
        using (Record record = view.Fetch())
        {
            record[1] = upgradeCode.ToString("B").ToUpperInvariant();
            view.Replace(record);
        }

        db.Commit();
    }
}

I took the above and made the following mock-up (very ugly, but it worked):

using (Database db = new Database(@"C:\Test.msi", DatabaseOpenMode.Direct))
{
    using (View view = db.OpenView("SELECT * FROM `Upgrade`", new object[0]))
    {
        view.Execute();
        using (Record record = view.Fetch())
        {
            record[1] = "{777888DD-1111-1111-1111-222222222222}";
            record[2] = "";
            record[3] = "4.0.1";
            record[4] = "";
            record[5] = "1";
            record[6] = "";
            record[7] = "WIX_UPGRADE_DETECTED";
            view.Replace(record);
        }

        db.Commit();

        using (Record record = view.Fetch())
        {
            record[1] = "{777888DD-1111-1111-1111-222222222222}";
            record[2] = "";
            record[3] = "";
            record[4] = "4.0.1";
            record[5] = "1";
            record[6] = "";
            record[7] = "WIX_DOWNGRADE_DETECTED";
            view.Replace(record);
        }

        db.Commit();
    }
}



回答2:


The SDK doc says:

UPDATE queries only work on nonprimary key columns.

UpgradeCode is the primary key for the Upgrade table.



来源:https://stackoverflow.com/questions/57773657/problem-with-modifying-an-msi-database-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!