0

In a .NET 5.0 framework project, I have referenced the following packages:

<PackageReference Include="Oracle.EntityFrameworkCore" Version="5.21.1" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.1" />

in ConfigureSettings method I have added this code:

services.AddDbContext<IMyDbContext, MyDbContext>((provider, options) =>
        {
            OracleConfiguration.OracleDataSources.Add("dev", "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP )(HOST = <host> )(PORT = 1521 )) (CONNECT_DATA = (SERVICE_NAME = DEV ) ) )");
            options.UseOracle(connectionString);
        });

services.AddScoped(sp => (MyDbContext)sp.GetRequiredService<IMyDbContext>());

services.AddEntityFrameworkOracle();

Later in my service, I am trying to query a simple result:

await _dataContext.MyTable.CountAsync(cancellationToken)

but I get the following error (Error message is in German):

Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-12154: TNS: Angegebener Connect Identifier konnte nicht aufgelöst werden

OracleInternal.Network.NetworkException (0x00002F7A): ORA-12154: TNS: Angegebener Connect Identifier konnte nicht aufgelöst werden

The same time I have created a connection in Visual Studio Server Explorer with the following Connection string:

Data Source=dev;Persist Security Info=True;User ID=*******;Password=***********;Unicode=True

and it's enough to get query data.

What do I wrong in my project setup?

3

1 Answer 1

2

the problem has been solved by omiting TnsName in the connection string

https://www.connectionstrings.com/net-framework-data-provider-for-oracle/omiting-tnsnamesora/

after the change I have also removed this code line:

OracleConfiguration.OracleDataSources.Add
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.