1006

Error 110 (open_failed) MsiOpenDatabase - error in the loop

Question:

I'm facing a problem in my program. I need to catch some infos about different MSIs, so I'm using the MSI Database functions from msi.dll.

In a loop, I'm creating a list of objects (called PackFile). Each object must contains infos about each file installed by the msi, and each list contains all the files installed by a given msi.

I have differents methods for all the data I need to have (like the component, componentcode, installlevel of the feature, etc.). But all the methods fail.

Here's a sample of one of those methods, this one's purpose is to find the component code of the file:

public string findComponentCode(string productCode, string ComponentName) { int pathLen = 512; StringBuilder path = new StringBuilder(pathLen); IntPtr phDatabase = IntPtr.Zero; IntPtr hView = IntPtr.Zero; IntPtr hRecord = IntPtr.Zero; int componentCodeLen = 512; StringBuilder componentCode = new StringBuilder(componentCodeLen); MsiGetProductInfo(productCode, "LocalPackage", path, ref pathLen); MsiOpenDatabase(path.ToString(), IntPtr.Zero, ref phDatabase); MsiDatabaseOpenView(phDatabase, "SELECT * FROM `Component`", ref hView); MsiViewExecute(hView, hRecord); while (MsiViewFetch(hView, ref hRecord) != 259) { int bufferLen = 512; StringBuilder buffer = new StringBuilder(bufferLen); MsiRecordGetString(hRecord, 1, buffer, ref bufferLen); if (String.Compare(buffer.ToString(), ComponentName) == 0) { MsiRecordGetString(hRecord, 2, componentCode, ref componentCodeLen); break; } } MsiViewClose(hView); MsiCloseHandle(hRecord); MsiCloseHandle(phDatabase); return componentCode.ToString(); }

This function is in a loop, in order to find the code for every files.

My problem is that at a moment there is an error, the MsiOpenDatabase function return 110 (open_failed), and I can't understand why... And every time it is at the same file of the same msi...

Can someone give me a hint ?

PS: I'm quite a newbie in C# and .NET programming...

Answer1:

I assume you've debugged this enough to see that you're getting the full path to the local package. So if all that's ok, well strictly speaking that last parameter is an out not a ref. So try:

IntPtr pHDatatabase; MsiOpenDatabase(filename, persist, out pHDatatabase);

that kind of thing - that's what I use. See this:

<a href="http://www.pinvoke.net/default.aspx/msi.MsiOpenDatabase" rel="nofollow">http://www.pinvoke.net/default.aspx/msi.MsiOpenDatabase</a>

And I can't see your interop definition, so you may need to post it if it's not as pinvoke.net describes it.

Recommend

  • Fetching all data from an Entity and printing only displays the last record
  • calculating sales, refund and breakages from SQL Server Tables
  • codeigniter - display database query result on same form using input data
  • Changewheel functionality How it works?
  • Java regex to remove SQL comments from a string
  • jQuery datepicker displaying a Buddhist date
  • What means “The app must be signed with a development identity” ?
  • How to add external data file into developing R package?
  • Java regex to remove SQL comments from a string
  • jquery datepicker onselect not working
  • Chrome extension file upload browse window position off screen
  • Load knockoutjs component using javascript
  • select query between two dates
  • How to get value of Woocommerce Stripe payment form that is integrated in iframe, to get the 4 last
  • llvm::DIInstruction getFilename returns filename with a directory, I just want the filename
  • Widget UI not updating in response to broadcast
  • DataGrid not scrolling smoothly
  • C++ NetBeans Run-Configuration passing arguments-issue
  • Pending Intent triggered by Alarm Manager seems to fire right away
  • What adapter to use for ExpandableListView with non-TextView views?
  • Use function defined in one cpp file in function defined in another cpp file in Rcpp
  • VBA Excel, loop through variables
  • converter json to two dimensional array
  • What is Eclipse's Declaration View used for?
  • How to set my toolbar fixed while scrolling android
  • AT Commands to Send SMS not working in Windows 8.1
  • Cannot Parse HTML Data Using Android / JSOUP
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • JTable with a ScrollPane misbehaving
  • how does django model after text[] in postgresql [duplicate]
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • apache spark aggregate function using min value
  • How can I remove ASP.NET Designer.cs files?
  • unknown Exception android
  • Sorting a 2D array using the second column C++
  • failed to connect to specific WiFi in android programmatically
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?