There is nothing special on connecting to Oracle Database Cloud Service other than establishing an SSH tunel.
Oracle provides some documentation:
Developing .NET Applications for Oracle Database as a Service
Connecting to a Database Cloud Service (DBaaS) Instance Through an SSH Tunnel
However you won't want to call putty o ssh from your .NET application. What you will want is to establish the SSH tunnel by c# code.
SSH.NET will help you on that.
Here you have c# .NET Core 2.0 sample code that establish an SSH tunel, connect to a portable database on Oracle Database Cloud Service and execute the hello world query:
Code: Select all
class Program
{
static void Main(string[] args)
{
var port = new ForwardedPortLocal("127.0.0.1", 1521, "localhost", 1521);
PrivateKeyFile file = new PrivateKeyFile(@"path to the private key file");
using (var client = new SshClient("the public ip address of your oracle database cloud", "oracle", file))
{
client.Connect();
client.AddForwardedPort(port);
port.Start();
var cnstring = "User Id=UserName;Password=UserPassword;Direct=true;Data Source=localhost;Port=1521;Service Name=PDB1.YouCloudIdentityDomain.oraclecloud.internal";
using (var cn = new Devart.Data.Oracle.OracleConnection(cnstring))
using (var cmd = new Devart.Data.Oracle.OracleCommand("SELECT 'Hello from Oracle Cloud' FROM DUAL", cn))
{
cn.Open();
Console.WriteLine(cmd.ExecuteScalar());
}
client.Disconnect();
}
}
}