vba 如何纠正无法在 Windows 7 上的 Access 2003 中加载 DAO DLL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9744024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 15:33:03  来源:igfitidea点击:

How to correct for inability to load DAO DLL in Access 2003 on Windows 7?

ms-accessvbawindows-7dao

提问by Timbuck

I have an application that uses the MS Access 2003 front end to connect to both a MS SQL and a Sybase database. This application uses VBA (Visual Basic 6) and this cannot be changed. We are in the midst of a conversion from Windows XP (where the application runs fine) to Windows 7.

我有一个应用程序,它使用 MS Access 2003 前端连接到 MS SQL 和 Sybase 数据库。此应用程序使用 VBA (Visual Basic 6) 并且无法更改。我们正处于从 Windows XP(应用程序运行良好)到 Windows 7 的转换过程中。

On Windows 7, attempts to connect to the Sybase databsae fail. The application uses a pass through query and when the failure occurs, I receive the following message:

在 Windows 7 上,尝试连接到 Sybase 数据库失败。应用程序使用传递查询,当失败发生时,我收到以下消息:

An unexpected error occurred in Call_SP.
Error number: 48
Error description: Error in loading DLL
Error source: Secure open security

The particular line of code where this is throwing the error is:

引发错误的特定代码行是:

For Each qryDef In dbLocal.QueryDefs

The items in this line of code are defined like this:

这行代码中的项目定义如下:

Dim dbLocal As Database
Dim qryDef As QueryDef

Set dbLocal = CurrentDb()

When originally launching the application, there was a missing reference for Microsoft DAO 3.6 Object Library. I copied the dao360.dll file to C:\Program Files (x86)\Common Files\Microsoft Shared\DAO, registered it using regsvr32.exe, and set the reference (Tools -> References) to this file.

最初启动应用程序时,缺少对 Microsoft DAO 3.6 对象库的引用。我将 dao360.dll 文件复制到 C:\Program Files (x86)\Common Files\Microsoft Shared\DAO,使用 regsvr32.exe 注册它,并将引用(工具 -> 引用)设置为该文件。

At this point, I suspect the problem may have something to do with user rights on this machine, but I'm stuck on where to start. Users do have "read and execute" rights on the dao360.dll file.

在这一点上,我怀疑问题可能与这台机器上的用户权限有关,但我不知道从哪里开始。用户确实对 dao360.dll 文件具有“读取和执行”权限。

We have a lot of legacy apps written in Access, so our systems use Access 2003, but Word, Excel, and Outlook 2010. We are moving to Windows 7 64-bit.

我们有很多用 Access 编写的旧应用程序,因此我们的系统使用 Access 2003,但使用 Word、Excel 和 Outlook 2010。我们正在迁移到 Windows 7 64 位。

采纳答案by Renaud Bompuis

If I was in your shoes, I would try the following:

如果我处于您的位置,我会尝试以下操作:

  1. Remove and re-install Access

    And I would run a registry cleaner like CCleaner to remove broken library reference from the registry before re-installing Access and applying all updates.
    The fact that the dao360.dll was missing or improperly registered shows that there is at least one installation issue on that machine.
    Also, remove and re-install your ODBC drivers for the other databases.

  2. Try on the same machine from a different user

    Create a new user on the machine, then log under that user and check if you still get the issue.

  3. Try from a different machine

    Use the same database, make sure the DAO references are selected, and try code query again.
    If it still doesn't work, then there is another issue somewhere, and it's not related necessarly to DAO.

  4. You mention using Sybase and SQL Server.

    Are the ODBC drivers functioning properly? Could there be some corruption there too on the machine?
    What if you create a new database and try a single pass-through query using the same connection string?

  5. 32 and 64 bits mixup

    Are you sure all dependent software and database drivers are installed for 32bit?
    If you are trying to access an ODBC data source that uses a 64bit driver from a 32bit app, it will fail.
    In Win7 x64 the ODBC console available from the Administrative Toolsin the Control Panelis not32bit!
    You need to create your DSN using C:\Windows\SysWOW64\odbcad32.exeinstead.

  1. 删除并重新安装访问

    在重新安装 Access 并应用所有更新之前,我会运行像 CCleaner 这样的注册表清理器来从注册表中删除损坏的库引用。
    dao360.dll 丢失或未正确注册这一事实表明该机器上至少存在一个安装问题。
    此外,删除并重新安装其他数据库的 ODBC 驱动程序。

  2. 在不同用户的同一台机器上尝试

    在机器上创建一个新用户,然后在该用户下登录并检查您是否仍然遇到问题。

  3. 从不同的机器尝试

    使用相同的数据库,确保选择了 DAO 引用,然后再次尝试代码查询。
    如果它仍然不起作用,那么某处还有另一个问题,它与 DAO 没有必然关系。

  4. 您提到使用 Sybase 和 SQL Server。

    ODBC 驱动程序是否正常运行?机器上是否也有一些损坏?
    如果您创建一个新数据库并使用相同的连接字符串尝试单个传递查询会怎样?

  5. 32 位和 64 位混合

    您确定所有相关软件和数据库驱动程序都安装为 32 位吗?
    如果您尝试从 32 位应用程序访问使用 64 位驱动程序的 ODBC 数据源,它将失败。
    在Win7的X64可从该ODBC控制台管理工具控制面板不是32位!
    您需要使用来创建您的 DSN C:\Windows\SysWOW64\odbcad32.exe

回答by Michal

Problem ocured when x86 and x64 version of OS/Access are instaled.

安装 x86 和 x64 版本的 OS/Access 时出现的问题。

  1. You need to create directory (I'm sure it does not exsit and You need administrative rights to do this): C:\Program Files\Common Files\microsoft shared\DAO
  2. Copy dao360.dll from C:\Program Files (x86)\Common Files\microsoft shared\DAO to the directory created in step (1)
  3. Now add reference in your VBA application.
  1. 您需要创建目录(我确定它不存在并且您需要管理权限才能执行此操作):C:\Program Files\Common Files\microsoft shared\DAO
  2. 将 dao360.dll 从 C:\Program Files (x86)\Common Files\microsoft shared\DAO 复制到步骤(1)中创建的目录
  3. 现在在您的 VBA 应用程序中添加引用。

回答by Philip Sheard

The solution that I came up with was to use weak typing, and to reference all DAO objects through CurrentDb. The only references I have in my project are VBA and the Microsoft Access Object Library, which are required anyway.It is a bit radical, but it does give you something that can be deployed on any platform.

我提出的解决方案是使用弱类型,并通过 CurrentDb 引用所有 DAO 对象。我在我的项目中唯一的参考是 VBA 和 Microsoft Access 对象库,无论如何它们都是必需的。它有点激进,但它确实为您提供了可以部署在任何平台上的东西。

The project of every newly created Access database includes a reference to a DAO library. But DAO library references are no longer updated when databases are deployed on different machines. That feature was broken in Access 2007, when the DAO library was renamed.

每个新创建的 Access 数据库的项目都包含对 DAO 库的引用。但是当数据库部署在不同的机器上时,DAO 库引用不再更新。当 DAO 库被重命名时,该功能在 Access 2007 中被破坏。

In your example, this would be:

在您的示例中,这将是:

Dim qryDef As Object
For Each qryDef In CurrentDb.QueryDefs

回答by Albert D. Kallal

There is no need to attempt to re-register the dao library here and doing such is a silly wild goose chase and amounts to wasting company resources. Installing Access 2003 on that computer should work just fine and installing 2003 on that computer will ALSO correctly install the DAO libraries (attempting to copy and re-register the DAO library has the potential to turn your computer into a complete mess here – don't do this and it not required).

没有必要在这里尝试重新注册道库,这样做是一种愚蠢的追逐,等于浪费公司资源。在该计算机上安装 Access 2003 应该可以正常工作,并且在该计算机上安装 2003 也将正确安装 DAO 库(尝试复制和重新注册 DAO 库有可能使您的计算机在这里变得一团糟——不要这样做,它不是必需的)。

There are either some broken references or perhaps the ADO library was placed higher up in the references as compared to the DAO library. In fact check the references in the VBA editor. If ADO is not being used, then remove the reference.

与 DAO 库相比,可能存在一些损坏的引用,或者 ADO 库在引用中的位置更高。实际上检查 VBA 编辑器中的引用。如果未使用 ADO,则删除引用。

Also if outlook is being used from this application then remove the outlook reference in this application. You REALLY need to use late binding for Outlook automation code.

此外,如果此应用程序正在使用 Outlook,则删除此应用程序中的 Outlook 引用。您真的需要对 Outlook 自动化代码使用后期绑定。

I have run Access 2003 on windows 7 x64 since the win 7 beta and I had zero problems here. This is nothing to do with x64 or win7, but only that of behaviors of a typical broken reference.

自从 win 7 beta 以来,我已经在 windows 7 x64 上运行了 Access 2003,我在这里遇到了零问题。这与 x64 或 win7 无关,而仅与典型损坏参考的行为有关。