Skip to Main Content
  • Questions
  • Local Web-App (ASP.NET Core with EF Core works flawlessly) Publishing to azure

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Pieter.

Asked: November 25, 2020 - 4:08 pm UTC

Last updated: November 30, 2020 - 2:20 am UTC

Version: Oracle.EntityFrameworkCore 2.19.90

Viewed 1000+ times

You Asked

When I've published the ASP.NET Core Web App to Azure I get the following Error when trying to use the oracle database.
NetworkException: ORA-12154: TNS:could not resolve the connect identifier specified

OracleInternal.Network.AddressResolution..ctor(string TNSAlias, SqlNetOraConfig SNOConfig, Hashtable ObTnsHT, Hashtable ObLdpHT, string instanceName, ConnectionOption CO)
OracleException: ORA-12154: TNS:could not resolve the connect identifier specified

OracleInternal.ConnectionPool.PoolManager<PM, CP, PR>.Get(ConnectionString csWithDiffOrNewPwd, bool bGetForApp, OracleConnection connRefForCriteria, string affinityInstanceName, bool bForceMatch)


I fix these errors by setting
TNS_ADMIN & WALLET_LOCATION in my Application settings (ENV)
I have also set WEBSITE_LOAD_USER_PROFILE

Then I get a new error when trying to run Oracle DB code.

An unhandled exception occurred while processing the request.
OracleException: Connection request timed out

OracleInternal.ConnectionPool.PoolManager<PM, CP, PR>.Get(ConnectionString csWithDiffOrNewPwd, bool bGetForApp, OracleConnection connRefForCriteria, string affinityInstanceName, bool bForceMatch)

This one I can't seem to figure out.

Does anyone have any pointers or things I can try ?
My connection string looks like this and works perfectly on the local setup.

"User Id=user;Password=password;Data Source=db202011081718_medium;"


and is injected here in startup.cs
            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseOracle(
                    Configuration.GetConnectionString("OracleDBContextConnection")));

I must be missing something, related to the azure/oracle specifics that aren't playing nice
I've watched this video 3/4 times
https://www.youtube.com/watch?v=-IkDuJy30mY

and Connor said...

From "db202011081718_medium" I assume you're using an autonomous database.

Can you confirm that you

- downloaded a connection file (zip)
- unzipped into a empty directory (let's assume x:\oracle)
- edited the sqlnet.ora to point to x:\oracle
- set TNS_ADMIN to x:\oracle

At that point, with the Oracle client installed you should be able to do "tnsping db202011081718_medium", eg

C:\>cd C:\oracle\cloud_cmcdonald1

C:\oracle\cloud_cmcdonald1>dir
 Volume in drive C is OS
 Volume Serial Number is 0F26-5E10

 Directory of C:\oracle\cloud_cmcdonald1

16/06/2020  11:37 AM    <DIR>          .
16/06/2020  11:37 AM    <DIR>          ..
16/06/2020  03:37 AM             6,733 cwallet.sso
16/06/2020  03:37 AM             6,688 ewallet.p12
16/06/2020  03:37 AM             3,275 keystore.jks
16/06/2020  03:37 AM               691 ojdbc.properties
16/06/2020  03:37 AM               317 README
16/06/2020  11:38 AM               125 sqlnet.ora
16/06/2020  03:37 AM             1,841 tnsnames.ora
16/06/2020  03:37 AM             3,336 truststore.jks

C:\oracle\cloud_cmcdonald1>grep WALLET sqlnet.ora
WALLET_LOCATION = (SOURCE = (METHOD = file) (METHOD_DATA = (DIRECTORY="C:\oracle\cloud_cmcdonald1")))

C:\oracle\cloud_cmcdonald1>set TNS_ADMIN=C:\oracle\cloud_cmcdonald1

C:\oracle\cloud_cmcdonald1>tnsping cmcdonald1_low

TNS Ping Utility for 64-bit Windows: Version 19.0.0.0.0 - Production on 27-NOV-2020 15:49:28

Copyright (c) 1997, 2020, Oracle.  All rights reserved.

Used parameter files:
C:\oracle\cloud_cmcdonald1\sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (description= (retry_count=20)(re....[rest of tns string]
OK (1360 msec)



Can you get to that point?

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Oracle does connect locally.

Pieter van Zyl, November 27, 2020 - 8:23 am UTC

I have followed all of those steps

This is an autonomous database, hosted in the oracle cloud.

Locally I can confirm that I have done these:

- downloaded a connection file (zip)
- unzipped into a empty directory (let's assume x:\oracle)
- edited the sqlnet.ora to point to x:\oracle
- set TNS_ADMIN to x:\oracle

and it works perfectly, connects to the web app without issues.

The problem is, this doesn't work when I deploy it to the Azure Web Services (Cloud hosting platform)

Where I have done the following which are requirements

- downloaded a connection file (zip)
- unzipped into a empty directory (let's assume x:\oracle)
- edited the sqlnet.ora to point to x:\oracle (for the web app location)
- set TNS_ADMIN to x:\oracle
-set WEBSITE_LOAD_USER_PROFILE to 1

I set TNS_ADMIN, to point to x:\oracle in the Environment Variables of the Cloud Service.
Which fixes the first set of mentioned errors.

Unfortunately that still causes


An unhandled exception occurred while processing the request.
OracleException: Connection request timed out

OracleInternal.ConnectionPool.PoolManager<PM, CP, PR>.Get(ConnectionString csWithDiffOrNewPwd, bool bGetForApp, OracleConnection connRefForCriteria, string affinityInstanceName, bool bForceMatch)



Which according to the youtube video and your github repos for ASP.Net core and azure is everything that needs to be set.

Connor McDonald
November 30, 2020 - 2:20 am UTC

In that case, I think you've done everything correctly. Its time for you to log an SR to pursue it further.

More to Explore

Administration

Need more information on Administration? Check out the Administrators guide for the Oracle Database