"Oracle.DataAccess.Client.OracleConnection"的类型初始值设定项引发了异常 [英] The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception
问题描述
我已经开发了一个使用Oracle Data Provider for .NET的应用程序.我将应用程序文件(.exe)和ODP库(Oracle.DataAccess.dll)复制到未安装Oracle客户端和ODP.NET的另一台计算机上.运行应用程序时,出现错误msg:"Oracle.DataAccess.Client.OracleConnection"的类型初始化程序引发了异常.
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)
...
是否必须在要运行应用程序的计算机上安装ODP.NET和Oracle客户端?如果是,是否还有其他方法无需安装它们,但仍然可以运行我的应用程序?
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?
谢谢
推荐答案
好,当您确定使用相同过程的其他应用程序可以正常工作时;在新应用程序上,确保您具有数据访问参考和三个dll文件...
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...
我从Oracle网站下载了 ODAC1120320Xcopy_32bit :
I downloaded ODAC1120320Xcopy_32bit this from the Oracle site:
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)
Reference: Oracle.DataAccess.dll (ODAC1120320Xcopy_32bit\odp.net4\odp.net\bin\4\Oracle.DataAccess.dll)
在您的项目中包含以下3个文件:
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)
- 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.
修复:突出显示所有三个文件,然后选择复制到输出" =复制(如果较新).我确实复制了较新的文件,因为其中一个dll大于100MB,我所做的任何更新都不会再次复制这些文件.
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");
}
有关Oracle nls_lang列表,请访问以下站点: https://docs.oracle .com/html/B13804_02/gblsupp.htm
For the Oracle nls_lang list, see this site: https://docs.oracle.com/html/B13804_02/gblsupp.htm
在那之后,一切都顺利进行.
After that, everything worked smooth.
希望对您有帮助.
这篇关于"Oracle.DataAccess.Client.OracleConnection"的类型初始值设定项引发了异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!