1

I need to be able to update a binary table and i do it like so:

View v = session.Database.OpenView("SELECT `Data` FROM `Binary` WHERE `Name` = '{0}'", binaryKeyName);

            v.Execute();

            var IsReadOnly = session.Database.IsReadOnly;

            Record r = v.Fetch();

            StreamReader reader = new StreamReader(r.GetStream("Data"));
            string text = reader.ReadToEnd();
            text = text.Replace(@"Test12345", "TTTest");

            byte[] byteArray = Encoding.ASCII.GetBytes(text);
            MemoryStream stream = new MemoryStream(byteArray);

Once I have the stream I would like to update database table. How do i do it?

Thanks

ShaneKm
  • 20,823
  • 43
  • 167
  • 296

1 Answers1

3

The dtf.chm documentation, which comes with WiX, contains the following sample on how to update the binary table:

Database db = null;
View view = null;
Record rec = null;
try
{
    db = new Database("product.msi", DatabaseOpenMode.Direct);
    view = db.OpenView("UPDATE `Binary` SET `Data` = ? WHERE `Name` = '{0}'", binName))
    rec = new Record(1);
    rec.SetStream(1, binFile);
    view.Execute(rec);
    db.Commit();
}
finally
{
    if (rec != null) rec.Close();
    if (view != null) view.Close();
    if (db != null) db.Close();
}
Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • do you have a link to that documentation?. what goes into "binFile" in my case?? thanks – ShaneKm Jan 28 '13 at 13:55
  • It's not online, as far as I know. It is in the DTF.chm file, which is installed together with WiX Toolset. See "Deployment Tools Foundation Development Guide" >> "Working with MSI Databases" article – Yan Sklyarenko Jan 28 '13 at 13:57
  • I get error opening database on this line: db = new Database(@"c:\Temp\WixSqlDeployment\Setup\bin\Debug\Setup.msi", DatabaseOpenMode.Direct); – ShaneKm Jan 28 '13 at 14:00
  • The system cannot open the device or file specified. Database="c:\Temp\WixSqlDeployment\Setup\bin\Debug\Setup.msi" – ShaneKm Jan 28 '13 at 14:06