Developing .NET Core Applications for Oracle Autonomous Database

Connecting from Visual Studio Code

Connect .NET Core applications to Oracle Autonomous Database (ADB) using Oracle Data Provider for .NET (ODP.NET) Core and Oracle Developer Tools for VS Code. This tutorial shows you how from the tools using either Always Free or paid ADB.

For instructions to connect .NET Framework applications to ADB, click here.
 

How to Connect

 

Download and Install Oracle Developer Tools for VS Code

  • Before installing the Oracle tools, download and install VS Code.
  • Click on the Extensions icon in the Activity Bar on the side of VS Code or use the View: Show Extensions command (Ctrl+Shift+X).
  • Type Oracle in the extension search bar.
  • Locate Oracle Developer Tools for VS Code and click Install.
  • When the installation is complete, restart Visual Studio Code.

Download Client Wallet, Configure Connectivity, and Connect

  • Create an Oracle cloud account and provision an ADB instance. Click on these links to walk you through these steps if you have not already completes these tasks.
  • Obtain your Client Credentials File: Go to the Administration Console for your Oracle Autonomous Database and click Download Client Credentials. Alternatively, obtain the credentials file from your administrator.
  • Unzip the credentials files into the directory that is set as "Config Files Location" in the Oracle Developer Tools for VS Code Extension Settings. By default this location is %USERPROFILE%\Oracle\network\admin on Windows, and ~/Oracle/network/admin on Linux and Mac.
  • To connect to Oracle Database from a .SQL or .PL/SQL file, press F1 to open Command Palette and select Oracle:Connect from the dropdown.
  • To connect from Oracle Database Explorer, click the plus sign button.
  • A connection dialog will open. In the Connection Type dropdown, select TNS Alias.
  • Make sure the TNS Admin Location field is set to the directory where you unzipped your credentials files. If not, change it.
  • Check the Use Wallet File checkbox and set the Wallet File Location to the same path as TNS Admin Location.
  • Select the alias name you wish to connect to, for example mydb_high, from the TNS Alias dropdown list. Note that if there are multiple Autonomous Database instances in your cloud account, you will see aliases for all instances.
  • Select Non-Administrator from the Role drop down list.
  • Enter the username and password. If you are new to Oracle Autonomous Database, use username admin.
  • Provide a connection name to be used to reference this connection in Database Explorer and elsewhere.
  • Click the Create Connection button.

Run Your Application

You can use the same TNS alias, username, and password to connect your .NET Core application to ADB.
Follow the below instructions to run the sample code in VS Code.
  • Install the VS Code C# extension if running the app from VS Code.
  • In the VS Code Terminal window, change to a directory to place your project files, such as using the "cd <directory location>" command.
  • Run “dotnet new console” from the command line to create a new project.
  • Run “dotnet add package Oracle.ManagedDataAccess.Core  -v 2.19.70” from the command line to add ODP.NET Core to the project.
  • Open program.cs and copy the ODP.NET Core sample code contents to this file and save.
  • Configure the sample code to connect to your ADB instance. Provide values for the following:
    • User Id (i.e. ADMIN)
    • Password (i.e. ADMIN password) 
    • Data Source (i.e. mydb_high)
    • OracleConfiguration.TnsAdmin (i.e. directory ADB credentials were unzipped to)
    • OracleConfiguration.WalletLocation (i.e. directory ADB credentials were unzipped to)
  • Execute the app by running “dotnet run” from the command line. You should see the database version number output as a result. Congratulations! You connected to Oracle Autonomous Database.
Note: All ODP.NET Core versions support connecting to ADB.

Get Help or Provide Feedback

More Resources