首先,我想说我对Oracle数据库一点都不熟悉,所以我的话可能选择不当,而且我对某些概念的理解可能是错误的...... 无论如何,我试图使用ODP.NET连接到Oracle 11g数据库,每次它都给我这个例外:
System.TypeInitializationException occurred
HResult=-2146233036
Message=The type initializer for 'OracleInternal.Network.AddressResolution' threw an exception.
Source=Kiwi.ServiceBase
TypeName=OracleInternal.Network.AddressResolution
StackTrace:
at OracleInternal.ConnectionPool.PoolManager`3.CreateNewPR(Int32 reqCount, Boolean bForPoolPopulation, ConnectionString csWithDiffOrNewPwd, String instanceName)
at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword)
at Oracle.ManagedDataAccess.Client.OracleConnection.Open()
at Kiwi.DataAccess.OracleDataService.get_DbConnection() in c:\Projects\Kiwi-Beta7-0\Kiwiweb\src\Common\ApplicationServices\DataService\OracleDataService.cs:line 28
InnerException: System.TypeInitializationException
HResult=-2146233036
Message=The type initializer for 'OracleInternal.Network.LDAP' threw an exception.
Source=Oracle.ManagedDataAccess
TypeName=OracleInternal.Network.LDAP
StackTrace:
at OracleInternal.Network.LDAP..ctor()
at OracleInternal.Network.AddressResolution..cctor()
InnerException: System.NullReferenceException
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Oracle.ManagedDataAccess
StackTrace:
at OracleInternal.Network.LDAP._LDAP(Hashtable dsMap)
at OracleInternal.Network.LDAP..cctor()
InnerException:
来自:
private System.Data.IDbConnection _dbConnection;
public override IDbConnection DbConnection
{
get
{
if (_dbConnection.State == ConnectionState.Closed)
_dbConnection.Open(); // Crash from HERE
return _dbConnection;
}
}
编辑其他信息:我也尝试在没有tnsname.ora文件的情况下进行连接。这是在数据库所在的同一服务器上运行的Windows服务。
我尝试了以下连接字符串,第一个在调试中工作(并且是由应用程序构造的连接字符串):
Data Source=demosyr20140329:1521/demosyr;User ID=SEI;password=manager;Pooling = False;
Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) (HOST=DEMOSYR20140329)(PORT=1521))(CONNECT_DATA=(SID=DEMOSYR)));User Id=system;Password=manager;
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=DEMOSYR20140329)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=DEMOSYR)));
Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DEMOSYR20140329)(PORT=1521))(CONNECT_DATA=(SID=DEMOSYR))); User Id=system;Password=manager;
User Id=system;Password=manager;Data Source=oracle
Data Source=system/manager@//DEMOSYR20140329:1521/DEMOSYR;
有什么想法吗?
答案 0 :(得分:7)
这家伙帮我解决了我的问题 https://pravsdatums.wordpress.com/2013/12/16/ocac-12c-and-visual-studio-developer-tools/#comment-1
解决方案是从sql.ora文件中的NAMES.DIRECTORY_PATH中删除LDAP。此文件位于客户端主目录中(此路径可在HLM / SOFTWARE / ORACLE下的注册表中的某个密钥上找到)。所以文件的内容来自
SQLNET.AUTHENTICATION_SERVICES= (none)
NAMES.DIRECTORY_PATH= (LDAP, TNSNAMES, EZCONNECT)
要
SQLNET.AUTHENTICATION_SERVICES= (none)
NAMES.DIRECTORY_PATH= (EZCONNECT, TNSNAMES)
现在它有效!我不知道为什么它在我的开发机器上工作(可能是因为没有安装Oracle)。
希望它可以帮助别人!
答案 1 :(得分:0)
除了如上所述修复sqlnet.ora之外,还请检查TNS_ADMIN环境变量是否指向Oracle客户端的正确network \ admin路径。一旦这是正确的,重新启动,一切都应该很好!
答案 2 :(得分:-1)
我的猜测是连接字符串是一个问题。一些建议: