当前位置:  开发笔记 > 编程语言 > 正文

ODP.NET连接异常

如何解决《ODP.NET连接异常》经验,为你挑选了1个好方法。

首先我想说我对Oracle数据库一点也不熟悉,所以我的选择可能很差,而且我对某些概念的理解可能是错误的...无论如何,我试图使用ODP连接到Oracle 11g数据库.NET,每次它给我这个例外:

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;

任何的想法 ?



1> Simon ML..:

这家伙帮我解决了我的问题 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.我有同样的问题!我的路径是:`"C:\ oracle\instantclient_11_1\SQLNET.ORA"`
我也不得不删除LDAP。我仍然遇到问题,但是重新启动IIS之后,它开始工作。这些文件似乎已被缓存,因此如果仍然有问题,请确保重新启动IIS。
推荐阅读
Chloemw
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有