错误 110 (open_failed) MsiOpenDatabase - 循环错误 [英] Error 110 (open_failed) MsiOpenDatabase - error in the loop

查看:36
本文介绍了错误 110 (open_failed) MsiOpenDatabase - 循环错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序遇到问题.我需要获取有关不同 MSI 的一些信息,因此我使用 msi.dll 中的 MSI 数据库函数.

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.

在一个循环中,我创建了一个对象列表(称为 PackFile).每个对象必须包含有关 msi 安装的每个文件的信息,每个列表包含给定 msi 安装的所有文件.

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.

我的问题是,某刻出现错误,MsiOpenDatabase函数返回110(open_failed),我不明白为什么...而且每次都是在同一个msi的同一个文件...

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:我是 C# 和 .NET 编程的新手...

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

推荐答案

我假设您已经对此进行了足够的调试,可以看到您获得了本地包的完整路径.所以如果一切正常,严格来说最后一个参数是一个 out 而不是 ref.所以试试:

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);

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

那种东西 - 这就是我使用的.看到这个:

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

http://www.pinvoke.net/default.aspx/msi.MsiOpenDatabase

而且我看不到你的互操作定义,所以如果它不是 pinvoke.net 描述的那样,你可能需要发布它.

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

这篇关于错误 110 (open_failed) MsiOpenDatabase - 循环错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆