“Oracle.DataAccess.Client.OracleConnection”的类型初始值设定项 抛出异常

发布于 2024-07-22 06:26:58 字数 682 浏览 12 评论 0原文

我开发了一个使用 Oracle Data Provider for .NET 的应用程序。 我将应用程序文件 (.exe) 和 ODP 库 (Oracle.DataAccess.dll) 复制到另一台未安装 Oracle 客户端和 ODP.NET 的计算机上。 当我运行该应用程序时,收到错误消息:“Oracle.DataAccess.Client.OracleConnection”的类型初始值设定项引发异常。

*****************Exception Text***************
System.TypeInitializationException: The type initlializer for 'Oracle.DataAccess.Client.OracleConnection at Oracle.DataAccess.Client.OracleConnection..cctor()
  --- End of inner exception stack trace ---
  at Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString)
  ...

我是否必须在要运行应用程序的计算机上安装 ODP.NET 和 Oracle 客户端? 如果是,是否有其他方法可以让我不必安装它们但仍然可以运行我的应用程序?

谢谢

I have developed an application that uses Oracle Data Provider for .NET. I copy the application file (.exe) and ODP library (Oracle.DataAccess.dll) on another computer that Oracle client and ODP.NET are NOT installed on. When I run the application, I got the error msg: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.

*****************Exception Text***************
System.TypeInitializationException: The type initlializer for 'Oracle.DataAccess.Client.OracleConnection at Oracle.DataAccess.Client.OracleConnection..cctor()
  --- End of inner exception stack trace ---
  at Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString)
  ...

Do I have to install ODP.NET and Oracle client on the computer that I want to run my application? If yes, is there other way that I don't have to install them but still can run my application?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

红焚 2024-07-29 06:26:58

最简单的方法!!!

  1. 右键单击项目并选择“管理 NuGet 包...”,
  2. 搜索 Oracle.ManagedDataAccess。 安装它。

如果您使用的是 Entity Framework 并且您的 Visual Studio 版本为 2012 或更高版本,则

  1. 再次搜索 Oracle.ManagedDataAccess .EntityFramework。
    安装它。
  2. 在 .cs 文件中使用以下命名空间:
    使用 Oracle.ManagedDataAccess.Client;
    使用 Oracle.ManagedDataAccess.EntityFramework;

完成。 现在重新启动您的视觉工作室并构建您的代码。

这些软件包有什么作用?
安装这些软件包后,无需安装其他 Oracle 客户端软件即可连接到数据库。

Easiest Way!!!

  1. Right click on project and select "Manage NuGet Packages..."
  2. Search for Oracle.ManagedDataAccess. Install it.

If you are using Entity Framework and your Visual Studio Version is 2012 or higher,then

  1. Again search for Oracle.ManagedDataAccess.EntityFramework.
    Install it.
  2. Use below name spaces in your .cs file:
    using Oracle.ManagedDataAccess.Client;
    using Oracle.ManagedDataAccess.EntityFramework;

Its done. Now restart your visual studio and build your code.

What do these packages do?
After installing these packages no additional Oracle client software is required to be installed to connect to database.

疯狂的代价 2024-07-29 06:26:58

Oracle Data Provider for .NET(来自 Oracle)和 < a href="http://msdn.microsoft.com/en-us/library/2d7h4ycx.aspx" rel="noreferrer">.NET Framework Data Provider for Oracle(来自 Microsoft)需要安装 Oracle 客户端机器。

Both Oracle Data Provider for .NET (from Oracle) and .NET Framework Data Provider for Oracle (from Microsoft) require Oracle Client installed on machine.

酸甜透明夹心 2024-07-29 06:26:58

好的,当您确定其他使用相同流程的应用程序可以正常工作时; 在您的新应用程序上,请确保您拥有数据访问参考和三个 dll 文件...

我从 Oracle 站点下载了 ODAC1120320Xcopy_32bit

http://www.oracle.com/technetwork/database/windows/downloads/utilsoft-087491.html

参考:Oracle.DataAccess.dll (ODAC1120320Xcopy_32bit\odp.net4\odp.net\bin\4\Oracle.DataAccess.dll)

在您的项目中包含这 3 个文件:

  • oci.dll (ODAC1120320Xcopy_32bit\instantclient_11_2\oci.dll)
  • oraociei11.dll (ODAC1120320Xcopy_32bit\instantclient_11_2\oraociei11.dll)
  • OraOps11w.dll (ODAC1120320Xcopy_32bit\odp.net4\bin\Ora操作11w .dll)

当我尝试使用正确的引用和文件创建另一个应用程序时,我会收到该错误消息。

修复:突出显示所有三个文件并选择“复制到输出”= 如果较新则复制。 我确实复制了较新的文件,因为其中一个 dll 超过 100MB,并且我所做的任何更新都不会再次复制这些文件。

我还遇到了注册表错误,这解决了它。

public void updateRegistryForOracleNLS()
{
    RegistryKey oracle = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\ORACLE");
    oracle.SetValue("NLS_LANG", "AMERICAN_AMERICA.WE8MSWIN1252");
}

有关 Oracle nls_lang 列表,请参阅此站点:https://docs.oracle.com/ html/B13804_02/gblsupp.htm

之后,一切顺利。

我希望它有帮助。

Ok, when you know for sure other applications that used the same process worked; on your new application make sure you have the data access reference and the three dll files...

I downloaded ODAC1120320Xcopy_32bit this from the Oracle site:

http://www.oracle.com/technetwork/database/windows/downloads/utilsoft-087491.html

Reference: Oracle.DataAccess.dll (ODAC1120320Xcopy_32bit\odp.net4\odp.net\bin\4\Oracle.DataAccess.dll)

Include these 3 files within your project:

  • oci.dll (ODAC1120320Xcopy_32bit\instantclient_11_2\oci.dll)
  • oraociei11.dll (ODAC1120320Xcopy_32bit\instantclient_11_2\oraociei11.dll)
  • OraOps11w.dll (ODAC1120320Xcopy_32bit\odp.net4\bin\OraOps11w.dll)

When I tried to create another application with the correct reference and files I would receive that error message.

The fix: Highlighted all three of the files and selected "Copy To Output" = Copy if newer. I did copy if newer since one of the dll's is above 100MB and any updates I do will not copy those files again.

I also ran into a registry error, this fixed it.

public void updateRegistryForOracleNLS()
{
    RegistryKey oracle = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\ORACLE");
    oracle.SetValue("NLS_LANG", "AMERICAN_AMERICA.WE8MSWIN1252");
}

For the Oracle nls_lang list, see this site: https://docs.oracle.com/html/B13804_02/gblsupp.htm

After that, everything worked smooth.

I hope it helps.

束缚m 2024-07-29 06:26:58

两个选项:

  • 在要运行程序的 PC 上安装 Oracle 客户端

  • 使用 Oracle.ManagedDataAccess.dll

您可以在 NuGet 上获取它(搜索“oracle Managed”)或下载 ODP.NET_Managed.zip(链接是测试版,但为您指明了正确的方向)

我使用它,以便我部署到 don 的计算机不需要安装Oracle客户端。

请注意,我认为这对于控制台应用程序来说很好,但如果您打算安装应用程序,这会很烦人,因此我在这种情况下安装客户端。

Two options:

  • Install Oracle client on the PC you want to run your program on

  • Use Oracle.ManagedDataAccess.dll

You can get it on NuGet (search 'oracle managed') or download ODP.NET_Managed.zip (link is to a beta version, but points you in the right direction)

I use this so that the computers I deploy onto don't need Oracle client installed.

N.B. in my opinion this is good for console apps but annoying if you intend to install your application, so I install the client in that case.

甜柠檬 2024-07-29 06:26:58

您需要安装 Oracle 客户端驱动程序才能使这些类正常工作。

可能有可以处理 Oracle 的第 3 方连接框架,也许其他人可能知道一些特定的框架。

You need the oracle client driver installed for those classes to work.

There might be 3rd party connection frameworks out there that can handle Oracle, perhaps someone else might know of some specific ones.

离旧人 2024-07-29 06:26:58

您需要一个 Oracle 客户端:(2016 年之前)http:// www.oracle.com/technology/oramag/oracle/08-nov/o68odpnet.html

(大约 2019 年)重命名为“Oracle Instant Client”https://www.oracle.com/database/technologies/instant-client/downloads.html

ゞ花落谁相伴 2024-07-29 06:26:58

这是一个古老但仍然相关的问题,虽然这里的答案很有帮助,但没有人的答案完全解决了OP的两个问题。

1. 我是否必须在要运行应用程序的计算机上安装 ODP.NET 和 Oracle 客户端?

- 如果您使用的是 ODP.NET,非托管。 这是您在 Oracle 客户端安装程序中选择“Oracle Data Provider for .NET”时通常安装的版本(例如)。 您可以从 Oracle 下载此文件(只需 google 即可:Oracle URL 经常更改)。

但是,如果您使用 ODP.NET,托管(并且您可能想使用这个),那么不需要,您只需要使用应用程序安装(或部署)ODP.NET,托管,而不是完整的 Oracle 客户端。 详情请参阅下文。

2. 如果是,是否有其他方法可以让我不必安装它们但仍然可以运行我的应用程序?

是的,至少有一种方法。 它是ODP.NET的托管端口。

不幸的是,通常的解决方法,包括 ODBC、Microsoft 的 Oracle Provider for .NET(是的,就是那个旧的、已弃用的)和 ODP.NET、非托管 DLL,都需要安装 Oracle 客户端。 直到我们在 Oracle 的朋友给了我们一个漂亮的小 (~5MB) DLL,它也是托管的。 这意味着不再需要部署 32 位和 64 位版本来配合 32 位和 64 位 Oracle 客户端! 当您针对 10.0.2.1(或其他)构建时,程序集绑定不再有问题,但您的客户安装了从 9i 一直到 12c 的一系列客户端,包括中间的“g”客户端),因为您可以直接发布它与您的应用程序一起使用,并通过 nuget 进行管理。

但是,如果您使用以 nuget 包形式提供的 ODP.NET Managed,则无需安装 Oracle 客户端。您只需要 ODP.NET Managed DLL。 如果您之前使用的是 ODP.NET,非托管 DLL,则切换起来非常容易:只需更改对托管 ODP.NET 的所有引用(csharp 中的 .csproj 文件等),然后更改任何 using 语句,例如:using Oracle.DataAccess.Client 变为 using Oracle.ManagedDataAccess.Client 就这样! (除非您据说在 ODP.NET、非托管的完整客户端中使用了一些更高级的数据库管理功能,我自己还没有这样做过,所以祝您好运......)。 并且还从您的 app.config/web.config 文件中删除所有那些烦人的 assemblyBindingRedirect 节点,再也不用担心那些垃圾了!

参考资料:

故障排除:

该错误通常意味着 ODP.NET 正常,但未找到或未安装 Oracle 客户端。 当体系结构不匹配时(安装了 32 位 Oracle 客户端,但尝试使用 64 位非托管 ODP.NET,反之亦然),也可能会发生这种情况。 由于权限问题和路径问题以及应用程序域(您的 Web 应用程序或 EXE 等)的其他问题,无法找到 Oracle DLL 来通过网络与 Oracle 实际通信(ODP.NET 非托管),也可能会发生这种情况。 DLL 基本上只是挂钩到 ADO 等内容的包装器)。

我发现此问题的常见解决方案:

应用程序是 64 位的?

  • 安装64位Oracle客户端(32位不行)

应用程序是32位的?

  • 安装 32 位 Oracle 客户端(64 位无法工作)

Oracle 客户端是否已安装为正确的架构?

  • 验证您的环境 PATH 和 ORACLE_HOME 变量,确保可以找到 Oracle(较新版本可能会使用注册表)
  • 验证 ORACLE_HOME 和注册表中的设置(请记住:注册表是 32 位或 64 位)位,因此请确保检查与您的应用程序匹配的那个!)
  • 验证 ORACLE_HOME 文件夹的权限。 如果您不知道它在哪里,请检查注册表。 我见过 ASP.NET 应用程序工作进程使用网络服务用户的情况,并且由于某种原因并排安装 32 位和 64 位客户端导致授权用户的权限从第一个客户端中删除/code> group.. 修复主文件夹上的权限修复了此问题。
  • 与往常一样,使用 SysInternals Process Monitor 可以方便地找出丢失或无法读取的文件。

This is an old, but still relevant question, and while the answers here are helpful no one answer fully addressed both of the OP's questions.

1. Do I have to install ODP.NET and Oracle client on the computer that I want to run my application?

YES - if you are using ODP.NET, Unmanaged. This is the version that you typically install when you choose "Oracle Data Provider for .NET" in the Oracle Client installer (for example). You Download this from Oracle (just google it: Oracle URLs change often).

But If you are using ODP.NET, Managed (and you probably want to use this one this instead) then No, you only need to install (or deploy) ODP.NET, Managed with the app, not the full Oracle Client. See below for details.

2. If yes, is there other way that I don't have to install them but still can run my application?

Yes, there is at least one way. And it is the Managed port of ODP.NET.

Unfortunately the usual workarounds, including ODBC, Microsoft's Oracle Provider for .NET (yes, that old, deprecated one), and the ODP.NET, Unmanaged DLL all require the Oracle client to be installed. It wasn't until our friends at Oracle gave us a nice little (~5MB) DLL that is also Managed. This means no more having to depoy 32-bit and 64-bit versions to go with 32-bit and 64-bit Oracle clients! And no more issues with assembly binding where you build against 10.0.2.1 (or whatever) but your customers install a range of clients from 9i all the way to 12c, including the 'g' ones in the middle) because you can just ship it with your app, and manage it via nuget.

But if you use ODP.NET, Managed which is available as a nuget package, then you do not need to install the Oracle Client. You only need the ODP.NET, Managed DLL. And if you were previously using the ODP.NET, Unmanaged DLL, it is very easy to switch: simply change all your references to the Managed ODP.NET (.csproj files in csharp, etc.), and then change any using statements, for example: using Oracle.DataAccess.Client becomes using Oracle.ManagedDataAccess.Client and that's it! (Unless you were supposedly using some of the more advanced DB management features in the full client that are exposed in the ODP.NET, Unmanaged, which I have not done myself, so good luck with that..). And also nuke all of those annoying assemblyBindingRedirect nodes from your app.config/web.config files and never sweat that junk again!

References:

Troubleshooting:

That error typically means ODP.NET was found OK, but Oracle client was not found or not installed. This could also occur when the architecture doesn't match (32-bit Oracle client is installed, but trying to use 64-bit Unmanaged ODP.NET, or vice versa). This can also happen due to permissions issues and path issues and other problems with the app domain (your web app or your EXE or whatever) not being able to find the Oracle DLLs to actually communicate with Oracle over the network (the ODP.NET Unmanaged DLLs are basically just wrappers for this that hook into ADO and stuff).

Common solutions I have found to this problem:

App is 64-bit?

  • Install 64-bit Oracle Client (32-bit one wont work)

App is 32-bit?

  • Install 32-bit Oracle Client (64-bit one wont work)

Oracle Client is already installed for the correct architecture?

  • Verify your environment PATH and ORACLE_HOME variables, make sure Oracle can be found (newer versions may use Registry instead)
  • Verify the ORACLE_HOME and settings in the Registry (And remember: Registry is either 32-bit or 64-bit, so make sure you check the one that matches your app!)
  • Verify permissions on the ORACLE_HOME folder. If you don't know where this is, check the Registry. I have seen cases where ASP.NET app worker process was using Network Service user and for some reason installing 32-bit and 64-bit clients side by side resulted in the permissions being removed from the first client for the Authorized Users group.. fixing perms on the home folder fixed this.
  • As always, it is handy to Use SysInternals Process Monitor to find out what file is missing or can't be read.
故事还在继续 2024-07-29 06:26:58

还要检查 machine.config 是否有旧的/错误的安装目标。 删除与此 DLL 相关的所有内容。

Check the machine.config too for old/bad installation targets. Remove everything related to this DLL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文