0
votes

I have a strange effect here. I'm trying to open an existing MSI-file using DTF assembly and it return error code 110 (ERROR_OPEN_FAILED). If I'm trying to get last error by MsiGetLastErrorRecord - it returns 0, i.e. there is no error.

For experiment, I've tried to open the same file using WinAPI directly (from a C++ application) and it works fine.

As far as I know DTF is used by a lot of people and I suppose there is no bug in it, so it should be some issue with my system/configuration.

I'm using Windows 10 and VS2012 with .NET 4.5

Any hints, what it could be?

PS: actually, from beginning I've tried to interop WinAPI by myself and I've got this result. Using of DTF was a try to illuminate my eventually wrong interoption.

Update: I've checked execution with ProcessMonitor and have seen that CreateFile fails with SHARING VIOLATION: Desired Access: Generic Read/Write Disposition: Open Options: Synchronous IO Non-Alert, Non-Directory File Attributes: N ShareMode: Read AllocationSize: n/a

Update 2: it was one of the most stuipid errors. The issue was because a property, that had opened a DB, was triggered from design mode. Now the issue is solved. Thank you all for help!

1
It looks like your update should be an answer: the file is already open elsewhere. If this surprises you, you should add more details about the scenario, including why you think it shouldn't already be open.Michael Urman
I agree with Michael, the file must have a lock on it. Can you post the actual code you use as well? Did you try to open the file read-only?Stein Åsmul

1 Answers

0
votes

From the DTF help file:

using (Database db = new Database("product.msi", DatabaseOpenMode.ReadOnly))
    {        string value = (string) db.ExecuteScalar(
        "SELECT `Value` FROM `Property` WHERE `Property` = '{0}'", propName);
    }

This should obviously work in read-only mode regardless if the file is locked elsewhere. There is also the convenient InstallPackage class that works with files and cabinets in the context of a compressed or uncompressed product layout:

using (InstallPackage pkg = new InstallPackage("d:\builds\product.msi",
DatabaseOpenMode.Transact))     
{
   //(find the rest of the sample in the DTF help file)
}

I would try both classes with the different DatabaseOpenModes (ReadOnly, Transact, Direct, Create, CreateDirect).