web analytics

Using ODP.NET Core with ASP.NET Core Web Applciations


codeling 1595 - 6639
@2022-06-10 15:35:37

ODP.NET Core is an ADO.NET driver that provides fast data access from Microsoft .NET Core clients to Oracle databases. It runs on both Windows and Linux. ODP.NET consists of a single 100% managed code dynamic-link library, Oracle.ManagedDataAccess.dll, available via NuGet deployment.

In this post, you will learn how to create an ASP.NET Core web application, download ODP.NET Core from nuget.org, configure ODP.NET using the OracleConfiguration class, and connect to the Oracle database.

Create ASP.NET Core Web Project in Visual Studio

1.Open Visual Studio. Click  'File'. Select New>Project.

2.Select Visual C#>.NET Core> ASP.NET Core Web Application. Rename the Web Application as  First_Web_Application and click OK.

3.Select Empty Project template and click OK.

4.First_Web_Application is created, you can explore the structure of the project in the Solution Explorer.

@2022-06-10 15:48:41

Download ODP.NET Core from Nuget.org

In this section, you will download the ODP.NET Core NuGet package into the application.

Right Click on Dependencies in the Solution Explorer and Select Manage NuGet packages.

Select Browse and search for Oracle.ManagedDataAccess.Core.

Select Oracle.ManagedDataAccess.Core and Click Install.

Click OK to start the installation.

Accept the license.

You can see the installed package in the Solution Explorer.

@2022-06-10 16:04:26

Add ConnectionStrings in the appsetting.json file

In your project’s appsettings.json file, add the following “DefaultConnection” string with your ODP.NET connection string.

"ConnectionStrings": {
    "DefaultConnection": "User Id=<USER ID>;Password=<PASSWORD>;Data Source=<Data Source>;Tns_Admin=<file path to tnsnames.ora>"

For the Data Source, you can use the full Oracle connect descriptor, a net service name, or Easy Connect (Plus). When using a net service name, you can set the TNS_ADMIN operating system environment variable or Tns_Admin connection string attribute to the directory where the tnsnames.ora and sqlnet.ora files are located.


You must Sign In to comment on this topic.

© 2024 Digcode.com