ODP.NET Connection exception

早过忘川 提交于 2019-12-21 12:17:13

问题


First I would like to say that I am not familiar at all with Oracle databases, so my words might be poorly chosen and my understanding of some concept might be wrong... Anyway, I am trying to connect to an Oracle 11g database using ODP.NET and every time it gives me this exception :

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:

Called from :

private System.Data.IDbConnection _dbConnection;
public override IDbConnection DbConnection
{
    get
    {
        if (_dbConnection.State == ConnectionState.Closed)
            _dbConnection.Open();        // Crash from HERE
        return _dbConnection;
    }
}

EDIT Additional info : am also trying to connect without the tnsname.ora file. This is a windows service running on the same server that the database is located on.

I tried the following connection strings, the first one works in debug (and is the one constructed by the application) :

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;

Any idea ?


回答1:


This guy helped me solve my problem https://pravsdatums.wordpress.com/2013/12/16/ocac-12c-and-visual-studio-developer-tools/#comment-1

The solution was to remove LDAP from NAMES.DIRECTORY_PATH in the sql.ora file. This file is located on your client home directory (this path can be found on one of the key in the registry under HLM/SOFTWARE/ORACLE). So the content of the file went from

SQLNET.AUTHENTICATION_SERVICES= (none)

NAMES.DIRECTORY_PATH= (LDAP, TNSNAMES, EZCONNECT)

To

SQLNET.AUTHENTICATION_SERVICES= (none)

NAMES.DIRECTORY_PATH= (EZCONNECT, TNSNAMES)

And now it works ! I don't know why it was working on my development machine (maybe because Oracle is not installed on it).

Hope it can help somebody else !




回答2:


My guess is the connection string is an issue. Some suggestions:

  1. Can you connect to the database using SqlPlus or SqlDeveloper locally?
  2. If the answer to (1) is true, then I would try to modify _dbConnection.ConnectionString directly in the code until I got it right. If you are using tnsnames.ora for sqlplus connections, I would take the code from there are put it in the connection string and verify the connection as a sanity check. I know this is not your ultimate objective, but you must start somewhere.
  3. If the answer to (1) is false, I would work on getting that connection right first before attempting a connection through ODP.Net.


来源:https://stackoverflow.com/questions/25508402/odp-net-connection-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!