Developing .NET Applications for Oracle Autonomous Database

These tutorials show you how to connect .NET applications to Oracle Autonomous Database (ADB) using Oracle Data Provider for .NET Core via the command line, with Visual Studio Code, and with Visual Studio. Also learn how to connect .NET Framework apps to ADB using Visual Studio and Oracle Data Provider for .NET. Visit Developing .NET Applications for Oracle Database (On-Premises) for a tutorial using an on-premises database.


    .NET Core Command Line

    Open all Close all

    This tutorial shows you how use the command line to connect .NET Core applications to Oracle Autonomous Database (ADB) using Oracle Data Provider for .NET (ODP.NET) Core. Follow the steps below:

  • 1. Provision an ADB Instance

    Click on the links below to walk through these steps if you have not yet provisioned an ADB instance. Remember the database name and password. You will use them to connect .NET to ADB.

    You may select the Always Free option to use the Always Free Oracle ADB. Choose the Shared Infrastructure deployment type, which will have the Sales History schema that the ODP.NET sample code uses.

  • 2. Obtain Client Credentials

    Below are the instructions to download the client credentials from the Oracle Cloud Console. Alternatively, obtain the credentials from your administrator.

    • From the Oracle Cloud Console, go to the Autonomous Database Details page of your Oracle Autonomous Database instance.
    • Click the DB Connection button.
    • A new window will appear. Click the Download Wallet button.
    • Enter a wallet password in the Password field and confirm the password in the Confirm password field. Then, click the Download button. The password must be at least 8 characters long and include at least 1 letter and either 1 numeric character or 1 special character. This password protects the downloaded client credentials wallet.
    • Save the credentials zip file to a secure location.
    • Unzip the credentials files into a directory in a secure location. You will need this directory location later on.
  • 3. Install the .NET Core SDK

  • 4. Build and Run a .NET Core Application

    • From a command line, create a new directory for your application and change into that directory.
    • Use the dotnet executable to create a new project (click the copy button in the lower right corner of the code box in the examples below to copy and paste the contents):
      dotnet new console
      
        
    • Add ODP.NET Core to the project:
      dotnet add package Oracle.ManagedDataAccess.Core
      
        
    • Open Program.cs in a text editor.
    • Replace the contents of the Program.cs file with the following code:
      
      
      
      using System;
      using Oracle.ManagedDataAccess.Client;
      
      namespace ODP.NET_Core_Autonomous
      {
          class Program
          {
              static void Main()
              {
                  //Enter your ADB's user id, password, and net service name
                  string conString = "User Id=<ADMIN>;Password=<MYPASSWORD>;Data Source=<mydb_high>;Connection Timeout=30;";
      
                  //Enter directory where you unzipped your cloud credentials
                  OracleConfiguration.TnsAdmin = @"<MYDIRECTORY>";
                  OracleConfiguration.WalletLocation = OracleConfiguration.TnsAdmin;
      
                  using (OracleConnection con = new OracleConnection(conString))
                  {
                      using (OracleCommand cmd = con.CreateCommand())
                      {
                          try
                          {
                              con.Open();
                              Console.WriteLine("Successfully connected to Oracle Autonomous Database");
                              Console.WriteLine();
      
                              cmd.CommandText = "select CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY, CUST_CREDIT_LIMIT " +
                                  "from SH.CUSTOMERS order by CUST_ID fetch first 20 rows only";
                              OracleDataReader reader = cmd.ExecuteReader();
                              while (reader.Read())
                                  Console.WriteLine(reader.GetString(0) + " " + reader.GetString(1) + " in " + 
                                      reader.GetString(2) + " has " + reader.GetInt16(3) + " in credit." );
                          }
                          catch (Exception ex)
                          {
                              Console.WriteLine(ex.Message);
                          }
                      }
                  }
              }
          }
      }
        
      
    • Modify Program.cs to include your ADB connection information:
      • User Id: Enter ADMIN which is the user created by default during the creation of Autonomous Database. (If you created another ADB user, you can use that user instead.)
      • Password: Enter user's password. If ADMIN user is used, enter the password that was provided during the Create Autonomous Database step while provisioning Autonomous Database.
      • Data Source: Enter the net service name such as DBName_high. DBName is Database Name entered during the Create Autonomous Database step while provisioning Autonomous Database.
      • OracleConfiguration.TnsAdmin: Enter the directory where the Client Credentials for Autonomous Database were unzipped to.
    • Save changes to Program.cs.
    • Run the app:
      dotnet run
      
        
    • You should see a message that you connected to ADB and customer information returned from the database. Congratulations! You have successfully queried the Oracle Autonomous Database.
    • This sample application uses the Sales History (SH) sample schema. SH is a data set suited for online transaction processing operations. The Star Schema Benchmark (SSB) sample schema is available for data warehousing operations. Both schemas are available with your shared ADB instance and do not count towards your storage. You can use any ADB user account to access these schemas.

      Note: If you connect to ADB from behind a firewall, you will likely encounter a connection timeout error. Set your ODP.NET network configuration to use an HTTP proxy to connect successfully to ADB. Learn how to do this in this ADB documentation section. Scroll down to the "Connections with an HTTP Proxy" section on the doc page.

    .NET Core with Visual Studio Code

    Open all Close all

    This tutorial shows you how to connect .NET Core applications to Oracle Autonomous Database (ADB) using Oracle Data Provider for .NET (ODP.NET) Core, Visual Studio Code, and the Oracle Developer Tools for VS Code extension. Follow the steps below:

  • 1. Provision an ADB Instance

    Click on the links below to walk through these steps if you have not yet provisioned an ADB instance. Remember the database name and password. You will use them to connect .NET to ADB.

    You may select the Always Free option to use the Always Free Oracle ADB. Choose the Shared Infrastructure deployment type, which will have the Sales History schema that the ODP.NET sample code uses.

  • 2. Obtain Client Credentials

    Below are the instructions to download the client credentials from the Oracle Cloud Console. Alternatively, obtain the credentials from your administrator.

    • From the Oracle Cloud Console, go to the Autonomous Database Details page of your Oracle Autonomous Database instance.
    • Click the DB Connection button.
    • A new window will appear. Click the Download Wallet button.
    • Enter a wallet password in the Password field and confirm the password in the Confirm password field. Then, click the Download button. The password must be at least 8 characters long and include at least 1 letter and either 1 numeric character or 1 special character. This password protects the downloaded client credentials wallet.
    • Save the credentials zip file to a secure location.
    • Unzip the credentials files into a directory in a secure location. You will need this directory location later on.
  • 3. Install the .NET Core SDK

  • 4. Install Oracle Developer Tools For VS Code

    • Launch Visual Studio Code. (You can install Visual Studio Code if you do not already have it.)
    • Open the Extensions Marketplace by clicking the icon in the Activity Bar on the left side of Visual Studio Code or use the View: Show Extensions command (Ctrl+Shift+X)
    • Enter oracle into the Marketplace search text box and press return.
    • Locate the Oracle Developer Tools for VS Code extension and click it to open the extension's page.
    • Click the Install button to install the extension. During the installation you may be prompted to install a specific version of .NET Core Runtime depending on what is already installed on your machine.
    • Close Visual Studio Code and reopen it.
  • 5. Connect to Oracle Autonomous Database

    • Click on the Database icon in the Activity Bar on the left side of Visual Studio Code to open Oracle Database Explorer
    • Click the plus sign (+) to open the connection dialog
    • Fill in the connection dialog:
      • Connection Type: TNS Alias
      • TNS Admin Location: Enter the path to the location where you unzipped the credentials files in step 2 above.
      • TNS Alias: Enter the net service name such as DBName_high. DBName is Database Name entered during the Create Autonomous Database step while provisioning Autonomous Database.
      • Use Wallet File: Check this box
      • Wallet File Location: Set to the same path you used in the TNS Admin Location field above
      • Role: Non-Administrator
      • User name: Enter ADMIN which is the user created by default during the creation of Autonomous Database. (If you created another ADB user, you can use that user instead.)
      • Password: Enter user's password. If ADMIN user is used, enter the password that was provided during the Create Autonomous Database step while provisioning Autonomous Database.
      • Save password: Check this box if desired
    • Click the Create Connection button
  • 6. View Oracle Database Explorer and Open a new SQL File

    • Click on the database icon in the Activity Bar on the left side of Visual Studio Code if Oracle Database Explorer is not open
    • Click on the connection node to expand it (labeled ADMIN.DBName_high)
    • Explore the ADMIN schema. (Note: We will be querying the SH schema later in this tutorial. If you wish to explore the SH schema, you can expand the Other Users node in Oracle Database Explorer and open the SH node.
    • Right click on the connection node and from the menu choose Open New SQL File
  • 7. Execute a SQL Statement

    • Copy and paste the following SQL statement into the SQL file (click the copy button in the lower right corner of the code box in the examples below to copy and paste the contents):
      select CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY, CUST_CREDIT_LIMIT from sh.customers order by CUST_ID fetch first 20 rows only
      
        
    • Right click on the line that contains the SQL statement and choose Execute SQL
    • View the results.
  • 8. Build and Run a .NET Core Application

    • From the Visual Studio Code menu choose View->Terminal to open the Terminal window. At the command prompt in the terminal, create a new directory for your application and change into that directory. Follow the steps below and continue entering commands into the terminal.
    • Use the dotnet executable to create a new project:
      dotnet new console
      
        
    • Add ODP.NET Core to the project:
      dotnet add package Oracle.ManagedDataAccess.Core
      
        
    • From the Visual Studio Code menu choose File->Open Folder and select the directory you created above.
    • The Visual Studio Code Explorer pane will open. Double click Program.cs to open it in the editor.
    • Replace the contents of the Program.cs file with the following code:
      
      
      
      using System;
      using Oracle.ManagedDataAccess.Client;
      
      namespace ODP.NET_Core_Autonomous
      {
          class Program
          {
              static void Main()
              {
                  //Enter your ADB's user id, password, and net service name
                  string conString = "User Id=<ADMIN>;Password=<MYPASSWORD>;Data Source=<mydb_high>;Connection Timeout=30;";
      
                  //Enter directory where you unzipped your cloud credentials
                  OracleConfiguration.TnsAdmin = @"<MYDIRECTORY>";
                  OracleConfiguration.WalletLocation = OracleConfiguration.TnsAdmin;
      
                  using (OracleConnection con = new OracleConnection(conString))
                  {
                      using (OracleCommand cmd = con.CreateCommand())
                      {
                          try
                          {
                              con.Open();
                              Console.WriteLine("Successfully connected to Oracle Autonomous Database");
                              Console.WriteLine();
      
                              cmd.CommandText = "select CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY, CUST_CREDIT_LIMIT " +
                                  "from SH.CUSTOMERS order by CUST_ID fetch first 20 rows only";
                              OracleDataReader reader = cmd.ExecuteReader();
                              while (reader.Read())
                                  Console.WriteLine(reader.GetString(0) + " " + reader.GetString(1) + " in " + 
                                      reader.GetString(2) + " has " + reader.GetInt16(3) + " in credit." );
                          }
                          catch (Exception ex)
                          {
                              Console.WriteLine(ex.Message);
                          }
                      }
                  }
              }
          }
      }
        
      
    • Modify Program.cs to include your ADB connection information:
      • User Id: Enter ADMIN which is the user created by default during the creation of Autonomous Database. (If you created another ADB user, you can use that user instead.)
      • Password: Enter user's password. If ADMIN user is used, enter the password that was provided during the Create Autonomous Database step while provisioning Autonomous Database.
      • Data Source: Enter the net service name such as DBName_high. DBName is Database Name entered during the Create Autonomous Database step while provisioning Autonomous Database.
      • OracleConfiguration.TnsAdmin: Enter the directory where the Client Credentials for Autonomous Database were unzipped to.
    • From the Visual Studio Code menu choose File-Save to save the changes to Program.cs.
    • From the terminal, run the app:
      dotnet run
      
        
    • You should see a message that you connected to ADB and customer information returned from the database. Congratulations! You have successfully queried the Oracle Autonomous Database.

    This sample application uses the Sales History (SH) sample schema. SH is a data set suited for online transaction processing operations. The Star Schema Benchmark (SSB) sample schema is available for data warehousing operations. Both schemas are available with your shared ADB instance and do not count towards your storage. You can use any ADB user account to access these schemas.

    Note: If you connect to ADB from behind a firewall, you will likely encounter a connection timeout error. Set your ODP.NET network configuration to use an HTTP proxy to connect successfully to ADB. Learn how to do this in this ADB documentation section. Scroll down to the "Connections with an HTTP Proxy" section on the doc page.

    .NET Core with Visual Studio

    Open all Close all

    This tutorial shows you how to connect .NET Core applications to Oracle Autonomous Database (ADB) using Oracle Data Provider for .NET (ODP.NET) Core, Visual Studio 2019, and the Oracle Developer Tools for Visual Studio extension. Follow the steps below.

    (Note: If you have already completed the tutorial for .NET Framework with Visual Studio, you can skip to the last step of this tutorial. The other steps are identical.)

  • 1. Install Oracle Developer Tools For Visual Studio

    • Install Visual Studio 2019 if you do not already have it.
    • Download Oracle Developer Tools for Visual Studio 19.3.2.
    • Open the downloaded zip file and extract the ODTforVS2019_193200.vsix file to a temporary location. Double click the vsix file to run the installer.
    • Once the installation is complete, launch Visual Studio 2019.
    • A dialog may appear stating that Oracle Developer Tools for Visual Studio needs to perform additional configuration. If it does, close Visual Studio then follow the prompts in the dialog. Once the dialog finishes, launch Visual Studio 2019 again.
  • 2. Connect to Oracle Cloud Infrastructure from Visual Studio

    • Follow these steps to create a cloud account if you do not already have one.
    • Follow these instructions to create a config file that will be used to connect to your Oracle cloud account from Oracle Developer Tools for Visual Studio.
    • In Visual Studio Server Explorer, right Click on the Oracle Cloud Infrastructure node in the tree control and choose Add New Account Entry in the menu. (If Server Explorer is not visible in Visual Studio, select View->Server Explorer from the Visual Studio menu. If Oracle Cloud Infrastructure node is not shown then Oracle Developer Tools for Visual Studio is not installed properly).
    • In the Add New OCI Account Entry dialog that appears, click the button next to the Configuration File: field to browse to your newly created config file. The dialog will populate with the contents of the config file.
    • Select a profile listed under Choose an OCI CLI profile (if more than one is listed). Then click OK.
    • In the Choose Default Compartment dialog that appears, choose the compartment where you would like to create a new ADB instance or where your ADB instance already exists. Click OK.
    • An entry for your account will now appear under the Oracle Cloud Infrastructure node in Server Explorer.
  • 3. Provision an ADB Instance

    If you already have an ADB instance that you would like to use, you can skip to step 4: Connect to Oracle Autonomous Database.

    • In Server Explorer, right click on Autonomous Transaction Processing Databases and choose Create New
    • Fill in the dialog:
      • Display Name: The display name of the database
      • Database Name: The name of the database
      • Always Free: Check this box to create an Always Free instance. If you do not wish to create an Always Free instance, set the CPU Core Count, Storage, Auto Scaling and License Type as desired.
      • Password: The password for ADMIN.
      • Confirm Password: The password for ADMIN.
    • Click the Create New button to create the database.
    • You will see an icon for your database instance appear in the tree control under the Autonomous Transaction Processing Databases node. It will contain an orange ball while it is starting up. The database will be ready to use when the orange ball inside the icon disappears.
  • 4. Connect to Oracle Autonomous Database

    • In Server Explorer, locate the Autonomous Database icon for the instance created in the Provision an ADB Instance step. (The green star indicates that the ADB instance is Always Free). If the icon is contains an orange ball, wait for it to become available (no colored ball). If you skipped the Provision an ADB Instance step and wish to use another Autonomous Database, the instance should be available (the icon should not show an orange or red colored ball).
    • Right click on the ADB icon and choose Create Data Connection from the menu.
    • In the Create Data Connection dialog, check the Download credentials files for the database check box and change the Files path if you desire to download the credentials file to a different location. Remember the path to your credentials files as you will use this later on in your .NET Core application. Press the Continue button.
    • The Connection Properties dialog opens with most fields pre-populated. Select a Data Source Name from the drop down and make a note of this name as it will be used in your .NET Core app later. Enter Username ADMIN and enter the password that you provided in the Provision an ADB Instance step. Then click OK.
    • A connection will appear in the Data Connections node in Server Explorer.
  • 5. Execute a SQL Statement

    In this step we will test a SQL statement that we will include in our application later. The sample application uses the Sales History (SH) sample schema. SH is a data set suited for online transaction processing operations. This schema is available with your shared ADB instance and do not count towards your storage. You can use any ADB user account to access these schemas.

    • In Server Explorer, under Data Connections, right click on the newly create connection node and select Query Window. The Query Window will open.
    • Copy and paste the following SQL statement into Query Window (click the copy button in the lower right corner of the code box in the examples below to copy and paste the contents):
      select CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY, CUST_CREDIT_LIMIT
      
      from sh.customers order by CUST_ID fetch first 20 rows only
        
    • Right click in the Query Window and choose Execute Query
    • View the results.
  • 6. Build and Run a .NET Core (Cross Platform) Application

      In this step you will build a .NET Core application that can run on Windows, Linux, and macOS.

    • From the Visual Studio menu choose File->New->Project. In the Create a new project dialog, enter console into the Search for templates field. Select the Console Application project type listed for C# and .NET Core. Then press the Next button.
    • In the Configure your new project dialog enter ODP.NET_Core_Autonomous for the Project Name and then press the Next button.
    • In the Additional Information dialog select .NET Core 3.1 for the Target Framework and then press the Create button.
    • After the new project opens, view Solution Explorer, right click on the Dependencies node and select Manage NuGet Packages (If you don't see Solution Explorer, go to the Visual Studio menu and select View->Solution Explorer)
    • In Nuget Package Manager, click Browse, then in the Search box, enter oracle.
    • Select Oracle.ManagedDataAccess.Core version 3.21.1 and then click the Install button. When the Preview Changes dialog opens click OK.
    • Replace the contents of the Program.cs file with the following code:
      
      
      
      using System;
      using Oracle.ManagedDataAccess.Client;
      
      namespace ODP.NET_Core_Autonomous
      {
          class Program
          {
              static void Main()
              {
                  //Enter your ADB's user id, password, and net service name
                  string conString = "User Id=<ADMIN>;Password=<MYPASSWORD>;Data Source=<mydb_high>;Connection Timeout=30;";
      
                  //Enter directory where you unzipped your cloud credentials
                  OracleConfiguration.TnsAdmin = @"<MYDIRECTORY>";
                  OracleConfiguration.WalletLocation = OracleConfiguration.TnsAdmin;
      
                  using (OracleConnection con = new OracleConnection(conString))
                  {
                      using (OracleCommand cmd = con.CreateCommand())
                      {
                          try
                          {
                              con.Open();
                              Console.WriteLine("Successfully connected to Oracle Autonomous Database");
                              Console.WriteLine();
      
                              cmd.CommandText = "select CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY, CUST_CREDIT_LIMIT " +
                                  "from SH.CUSTOMERS order by CUST_ID fetch first 20 rows only";
                              OracleDataReader reader = cmd.ExecuteReader();
                              while (reader.Read())
                                  Console.WriteLine(reader.GetString(0) + " " + reader.GetString(1) + " in " + 
                                      reader.GetString(2) + " has " + reader.GetInt16(3) + " in credit." );
                          }
                          catch (Exception ex)
                          {
                              Console.WriteLine(ex.Message);
                          }
                      }
                  }
              }
          }
      }
        
      
    • Modify Program.cs to include your ADB connection information:
      • User Id: Enter ADMIN which is the user created by default during the creation of Autonomous Database. (If you created another ADB user, you can use that user instead.)
      • Password: Enter user's password. If ADMIN user is used, enter the password that was provided during the Provision an ADB Instance step above.
      • Data Source: Enter the net service name such as DBName_high. This is the Data Source Name you selected in the Create Data Connection dialog in the Connect to Oracle Autonomous Database step above and is seen in the Server Explorer data connections. (DBName is the Database Name entered during the Provision an ADB Instance step)
      • OracleConfiguration.TnsAdmin: Enter the directory where the Client Credentials for Autonomous Database were downloaded to in the Connect to Oracle Autonomous Database step.
    • From the Visual Studio menu choose Debug->Start Debugging (or press F5) to save, build and then run the application.
    • You should see a message that you connected to ADB and customer information returned from the database. Congratulations! You have successfully queried the Oracle Autonomous Database.

    Note: If you connect to ADB from behind a firewall, you will likely encounter a connection timeout error. Set your ODP.NET network configuration to use an HTTP proxy to connect successfully to ADB. Learn how to do this in this ADB documentation section. Scroll down to the "Connections with an HTTP Proxy" section on the doc page.

    .NET Framework with Visual Studio

    Open all Close all

    This tutorial shows you how to connect .NET Framework applications to Oracle Autonomous Database (ADB) using Oracle Data Provider for .NET (ODP.NET), Visual Studio 2019, and the Oracle Developer Tools for Visual Studio extension. Follow the steps below.

    (Note: If you have already completed the tutorial for .NET Core with Visual Studio, you can skip to the last step of this tutorial. The other steps are identical.)

  • 1. Install Oracle Developer Tools For Visual Studio

    • Install Visual Studio 2019 if you do not already have it.
    • Download Oracle Developer Tools for Visual Studio 19.3.2.
    • Open the downloaded zip file and extract the ODTforVS2019_193200.vsix file to a temporary location. Double click the vsix file to run the installer.
    • Once the installation is complete, launch Visual Studio 2019.
    • A dialog may appear stating that Oracle Developer Tools for Visual Studio needs to perform additional configuration. If it does, close Visual Studio then follow the prompts in the dialog. Once the dialog finishes, launch Visual Studio 2019 again.
  • 2. Connect to Oracle Cloud Infrastructure from Visual Studio

    • Follow these steps to create a cloud account if you do not already have one.
    • Follow these instructions to create a config file that will be used to connect to your Oracle cloud account from Oracle Developer Tools for Visual Studio.
    • In Visual Studio Server Explorer, right Click on the Oracle Cloud Infrastructure node in the tree control and choose Add New Account Entry in the menu. (If Server Explorer is not visible in Visual Studio, select View->Server Explorer from the Visual Studio menu. If Oracle Cloud Infrastructure node is not shown then Oracle Developer Tools for Visual Studio is not installed properly).
    • In the Add New OCI Account Entry dialog that appears, click the button next to the Configuration File: field to browse to your newly created config file. The dialog will populate with the contents of the config file.
    • Select a profile listed under Choose an OCI CLI profile (if more than one is listed). Then click OK.
    • In the Choose Default Compartment dialog that appears, choose the compartment where you would like to create a new ADB instance or where your ADB instance already exists. Click OK.
    • An entry for your account will now appear under the Oracle Cloud Infrastructure node in Server Explorer.
  • 3. Provision an ADB Instance

    If you already have an ADB instance that you would like to use, you can skip to step 4: Connect to Oracle Autonomous Database.

    • In Server Explorer, right click on Autonomous Transaction Processing Databases and choose Create New
    • Fill in the dialog:
      • Display Name: The display name of the database
      • Database Name: The name of the database
      • Always Free: Check this box to create an Always Free instance. If you do not wish to create an Always Free instance, set the CPU Core Count, Storage, Auto Scaling and License Type as desired.
      • Password: The password for ADMIN.
      • Confirm Password: The password for ADMIN.
    • Click the Create New button to create the database.
    • You will see an icon for your database instance appear in the tree control under the Autonomous Transaction Processing Databases node. It will contain an orange ball while it is starting up. The database will be ready to use when the orange ball inside the icon disappears.
  • 4. Connect to Oracle Autonomous Database

    • In Server Explorer, locate the Autonomous Database icon for the instance created in the Provision an ADB Instance step. (The green star indicates that the ADB instance is Always Free). If the icon is contains an orange ball, wait for it to become available (no colored ball). If you skipped the Provision an ADB Instance step and wish to use another Autonomous Database, the instance should be available (the icon should not show an orange or red colored ball).
    • Right click on the ADB icon and choose Create Data Connection from the menu.
    • In the Create Data Connection dialog, check the Download credentials files for the database check box and change the Files path if you desire to download the credentials file to a different location. Remember the path to your credentials files as you will use this later on in your .NET Framework application. Press the Continue button.
    • The Connection Properties dialog opens with most fields pre-populated. Select a Data Source Name from the drop down and make a note of this name as it will be used in your .NET Core app later. Enter Username ADMIN and enter the password that you provided in the Provision an ADB Instance step. Then click OK.
    • A connection will appear in the Data Connections node in Server Explorer.
  • 5. Execute a SQL Statement

    In this step we will test a SQL statement that we will include in our application later. The sample application uses the Sales History (SH) sample schema. SH is a data set suited for online transaction processing operations. This schema is available with your shared ADB instance and do not count towards your storage. You can use any ADB user account to access these schemas.

    • In Server Explorer, under Data Connections, right click on the newly create connection node and select Query Window. The Query Window will open.
    • Copy and paste the following SQL statement into Query Window (click the copy button in the lower right corner of the code box in the examples below to copy and paste the contents):
      select CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY, CUST_CREDIT_LIMIT
      
      from sh.customers order by CUST_ID fetch first 20 rows only
        
    • Right click in the Query Window and choose Execute Query
    • View the results.
  • 6. Build and Run a .NET Framework Application

      In this step you will build a .NET Framework application.

    • From the Visual Studio menu choose File->New->Project. In the Create a new project dialog, enter console into the Search for templates field. Select the Console Application project type listed for C# and .NET Framework. Then press the Next button.
    • In the Configure your new project dialog enter ODP.NET_Autonomous for the Project Name and then press the Next button.
    • In the Framework dropdown choose the version of the .NET Framework (.NET Framework 4.8 is recommended, if available) and then press the Create button.
    • After the new project opens, view Solution Explorer, right click on the References node and select Manage NuGet Packages (If you don't see Solution Explorer, go to the Visual Studio menu and select View->Solution Explorer)
    • In Nuget Package Manager, click Browse, then in the Search box, enter oracle.
    • Select Oracle.ManagedDataAccess version 19.11.0 and then click the Install button.
    • Replace the contents of the Program.cs file with the following code:
      
      
      
      using System;
      using Oracle.ManagedDataAccess.Client;
      
      namespace ODP.NET_Autonomous
      {
          class Program
          {
              static void Main()
              {
                  //Enter your ADB's user id, password, and net service name
                  string conString = "User Id=<ADMIN>;Password=<MYPASSWORD>;Data Source=<mydb_high>;Connection Timeout=30;";
      
                  //Enter directory where you unzipped your cloud credentials
                  OracleConfiguration.TnsAdmin = @"<MYDIRECTORY>";
                  OracleConfiguration.WalletLocation = OracleConfiguration.TnsAdmin;
      
                  using (OracleConnection con = new OracleConnection(conString))
                  {
                      using (OracleCommand cmd = con.CreateCommand())
                      {
                          try
                          {
                              con.Open();
                              Console.WriteLine("Successfully connected to Oracle Autonomous Database");
                              Console.WriteLine();
      
                              cmd.CommandText = "select CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY, CUST_CREDIT_LIMIT " +
                                  "from SH.CUSTOMERS order by CUST_ID fetch first 20 rows only";
                              OracleDataReader reader = cmd.ExecuteReader();
                              while (reader.Read())
                                  Console.WriteLine(reader.GetString(0) + " " + reader.GetString(1) + " in " + 
                                      reader.GetString(2) + " has " + reader.GetInt16(3) + " in credit." );
                          }
                          catch (Exception ex)
                          {
                              Console.WriteLine(ex.Message);
                          }
                      }
                  }
              }
          }
      }
        
      
    • Modify Program.cs to include your ADB connection information:
      • User Id: Enter ADMIN which is the user created by default during the creation of Autonomous Database. (If you created another ADB user, you can use that user instead.)
      • Password: Enter user's password. If ADMIN user is used, enter the password that was provided during the Provision an ADB Instance step above.
      • Data Source: Enter the net service name such as DBName_high. This is the Data Source Name you selected in the Create Data Connection dialog in the Connect to Oracle Autonomous Database step above and is seen in the Server Explorer data connections. (DBName is the Database Name entered during the Provision an ADB Instance step)
      • OracleConfiguration.TnsAdmin: Enter the directory where the Client Credentials for Autonomous Database were downloaded to in the Connect to Oracle Autonomous Database step.
    • From the Visual Studio menu choose Debug->Start Without Debugging (or press Control-F5) to save, build and then run the application.
    • You should see a message that you connected to ADB and customer information returned from the database. Congratulations! You have successfully queried the Oracle Autonomous Database.

    Note: If you connect to ADB from behind a firewall, you will likely encounter a connection timeout error. Set your ODP.NET network configuration to use an HTTP proxy to connect successfully to ADB. Learn how to do this in this ADB documentation section. Scroll down to the "Connections with an HTTP Proxy" section on the doc page.