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?
HOST = devin your TNS connect string. Basically the connect string is simply incorrect and you have to get it right