Oracle released a beta version driver ODP for dotnet core 2(Finally!). But I can't make it work. Does anybody did it? If yes, please send me the code or help me fixing this one \o
Useful: I am using Visual Code, project "dotnet new mvc" (.net 2) and I installed Oracle.ManagedDataAccess.Client
via Nuget Add Package facility (CTRL + P, ...)
Here my code:
public static OracleConnection AbrirSigmaUser(AutenticacaoModel autenticacao)
{
try
{
string _connectionString;
_connectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.15)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=databaseName)));User Id=UserName;Password=***;";
OracleConnection conexao = new OracleConnection();
conexao.ConnectionString = _connectionString;
//right here the program exit
conexao.Open();
return conexao;
}
catch (System.Exception ex)
{
throw new Exception("Não foi possível conectar ao banco de dados!" + "\nErro: " + ex.Message);
}
}
The compiler was throwing a lot of exceptions about missing dlls, so I installed them via Nuget Add Package facility:
//required for connection
using Oracle.ManagedDataAccess.Client;
using System.Configuration;
using System.Security.Permissions;
using System.Security.Principal;
After adding all dlls asked, the program goes to conexao.Open() and never comes back, throwing an unhandled exception:
Unhandled Exception: System.TypeLoadException: Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at OracleInternal.ConnectionPool.PoolManager`3.CreateNewPRThreadFunc(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
The program '[8860] Sensatta-Analytcs.dll' has exited with code 0 (0x0).
Is all of it really needed to make a simple connection?
If there's something missing(e.g code samples) in order to figure out my issue, just tell me!
For me, the solution was to install the Oracle.ManagedDataAccess.Core
NuGet package only. I had Oracle.ManagedDataAccess
installed as well and I needed to uninstall them to fix the error.
As @Lesiak stated, I used the wrong package (the right one is Oracle.ManagedDataAccess.Core.dll
). But that is an error someone else might fall in too. Because when you download the zip file from Oracle Link the dll name is Oracle.ManagedDataAccess.dll
instead of Oracle.ManagedDataAccess.Core.dll
that's error prone.
Install Oracle.ManagedDataAccess.Core nuget package to your project.
Make sure code below is included in your .csproj file:
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.1" />
Also uninstall "Oracle.ManagedDataAccess" from your project.
Make sure code below is removed from your .csproj file:
<PackageReference Include="Oracle.ManagedDataAccess" Version="19.10.1" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With