ericmend / oracleClientCore-2.0

Unofficial Oracle Client for .Net Core
MIT License
31 stars 6 forks source link

OracleException: Could not allocate the Oracle environment #11

Open juniormayhe opened 6 years ago

juniormayhe commented 6 years ago

I am having issues with this package. When Dapper tries to open connection (or I try to open it manually in debug mode), Visual Studio 2017 (under Windows 10) fires this exception:

OracleException: Could not allocate the Oracle environment.
System.Data.OracleClient.Oci.OciGlue.CreateConnection(OracleConnectionInfo conInfo)
System.Data.OracleClient.OracleConnectionPoolManager.CreateConnection(OracleConnectionInfo info)
System.Data.OracleClient.OracleConnectionPool.GetConnection()
System.Data.OracleClient.OracleConnection.Open()
Dapper.SqlMapper+<QueryImpl>d__136.MoveNext() in SqlMapper.cs
System.Collections.Generic.List.AddEnumerable(IEnumerable<T> enumerable)
System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)

So it seems CreateConnection method is firing an error.

Connection string:

string connectionString = "Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.227)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = MYSERVICENAME)));User ID=myuser;Password=mypass;Unicode=True";
con = new OracleConnection(connectionString); //ok here 
con.Open(); //fails

Oracle client 12c is already installed here, other clients and software can connect to Oracle without any issues.

Not sure if this is related to environment variables. I have set all known oracle variables (TNS_ADMIN, ORACLE_HOME, ORACLE_BASE). I also had run Visual Studio as administrator but the exception keeps showing up.

The oracle platform seems to be really old and disheartening. :disappointed:

alissonsolitto commented 6 years ago

This tutorial is in Portuguese because I am Brazilian. In this tutorial I am not using Dapper, but in my actual application I have used this configuration along with Dapper and it worked very well.

Blog: https://solitto.com.br/csharp/oracle-data-provider-net-core/ GitHub: https://github.com/alissonsolitto/ProviderOracle

That's the part that can help you.

We must define the environment variables to reference the Oracle Client .DLL. In the example below the Oracle Instant Client folder is located in "C: \ instantclient_12_2".

LD_LIBRARY_PATH = "C:\instantclient_12_2"
OCI_HOME = "C:\instantclient_12_2"
OCI_LIB_DIR = "C:\instantclient_12_2"
PATH = "C:\instantclient_12_2"
NLS_LANG = "PORTUGUESE_BRAZIL.WE8MSWIN1252"

The NLS_LANG variable is important for correct encoding of text fields.