Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection request timeout error connecting to Autonomous Database #225

Closed
madelson opened this issue Dec 11, 2021 · 3 comments
Closed

Connection request timeout error connecting to Autonomous Database #225

madelson opened this issue Dec 11, 2021 · 3 comments

Comments

@madelson
Copy link

I am trying to follow the instructions here and the sample here to use .NET Core to connect to an Autonomous Database in Oracle cloud.

However, the connection attempt fails with:

Oracle.ManagedDataAccess.Client.OracleException (0x80004005): Connection request timed out
   at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
   at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
   at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword, OracleConnection connRefForCriteria)
   at Oracle.ManagedDataAccess.Client.OracleConnection.Open()
   at UserQuery.Main() in C:\Users\mikea_000\AppData\Local\Temp\LINQPad6\_khszaeot\wvhmgd\LINQPadQuery:line 30

Here is the C# code I'm using to connect:

//Demo: ODP.NET Core application that connects to Oracle Autonomous DB

//Enter user id and password, such as ADMIN user	
string conString = "User Id=ADMIN;Password=MyAdminPassword;" +

//Enter net service name for data source value
"Data Source=dltest_high;";

OracleConfiguration.TraceFileLocation = @"C:\Users\mikea_000\Downloads";
OracleConfiguration.TraceLevel = 7;

using (OracleConnection con = new OracleConnection(conString))
{
	using (OracleCommand cmd = con.CreateCommand())
	{
		try
		{
			//Enter directory where the tnsnames.ora and sqlnet.ora files are located
			OracleConfiguration.TnsAdmin = @"C:\Users\mikea_000\Downloads\Wallet_DLTest";

			//Alternatively, connect descriptor and net service name entries can be placed in app itself
			//To use, uncomment below and enter the DB machine port, hostname/IP, service name, and distinguished name
			//Lastly, set the Data Source value to "autonomous"
			//OracleConfiguration.OracleDataSources.Add("autonomous", "(description=(address=(protocol=tcps)(port=<PORT>)(host=<HOSTNAME/IP>))(connect_data=(service_name=<SERVICE NAME>))(security=(ssl_server_cert_dn=<DISTINGUISHED NAME>)))");                       

			//Enter directory where wallet is stored locally
			OracleConfiguration.WalletLocation = @"C:\Users\mikea_000\Downloads\Wallet_DLTest";

			con.Open();

			Console.WriteLine("Successfully connected to Oracle Autonomous Database");

			//Retrieve database version info
			cmd.CommandText = "SELECT BANNER FROM V$VERSION";
			OracleDataReader reader = cmd.ExecuteReader();
			reader.Read();
			Console.WriteLine("Connected to " + reader.GetString(0));
		}
		catch (Exception ex)
		{
			Console.WriteLine(ex.ToString());
		}
	}
}

I've attached the trace file as well
LINQPAD6.QUERY.EXE_PID_11196_DATE_2021_12_11_TIME_11_09_24_882805.trc.zip
.

@alexkeh
Copy link
Member

alexkeh commented Dec 11, 2021

It looks like you encountered an ORA-12506 TNS: listener rejected connection based on service ACL filtering.

The most common reason is if you have an ACL setup for your ADB such that it only allows access to certain IPs, CIDR blocks, VCN, etc. Enable your specific IP or you can disable ACL. You will see this setting on the ADB configuration page, such as what you see here:

ACL

If you work at home, whatismyip will give your actual IP address.
.

@madelson
Copy link
Author

Worked like a charm. Thanks @alexkeh ! If this is determinable from the trace, it would be great to surface it in the exception message rather than just saying "request timed out". Do you agree?

@alexkeh
Copy link
Member

alexkeh commented Dec 11, 2021

The timeout is the first error that was hit. It should be the exception returned. The ORA-12506 was the second error. If the timeout was increased to two minutes long, then you should see the ORA-12506 as the first exception.

The ODP.NET default connection timeout, 15 seconds, is fairly low for the purposes of troubleshooting connectivity issues. The default is designed for a typical runtime experience in which an app wouldn't want a user to have to wait too long before returning a result.

@alexkeh alexkeh closed this as completed Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants