Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Welcome to our complete solution tutorial on integrating C# Devart.Data.Oracle with IronPDF to create comprehensive applications, focusing on Oracle-based database applications. This tutorial describes a guide designed for beginners interested in leveraging the power of Oracle databases in their .NET Framework and .NET Core projects. Devart.Data.Oracle is a powerful data provider that enables direct access to Oracle databases.
C# Devart.Data.Oracle is a library that simplifies Oracle database operations. It's for developers who need to interact with Oracle databases. This library offers advanced features. It streamlines database connectivity. It enhances data manipulation. This makes it a valuable tool for C# developers.
Explore IronPDF's Features for PDF Generation as a tool that allows C# developers to create, edit, and read PDF files. It integrates easily with .NET applications. IronPDF helps in generating PDFs from HTML. It provides a way to work with PDF files programmatically.
Both tools serve different purposes. C# Devart.Data.Oracle focuses on Oracle database interactions. IronPDF focuses on PDF file manipulation. Together, they enhance the capabilities of C# developers. They address two distinct needs in software development. This article will primarily focus on C# Devart.Data.Oracle.
To start using C# Devart.Data.Oracle, a renowned Oracle Database Provider, you first need to add it to your .NET Core project through Visual Studio's Solution Explorer. This process is straightforward. Go to the NuGet Package Manager. Search for "Devart.Data.Oracle". Install the package to leverage DotConnect for Oracle and Dataset tools. This action adds the library to your project. Now you can begin using its features.
Let's look at a simple example. This will demonstrate how to connect to an Oracle database. We'll execute a query. Here's a basic example:
using Devart.Data.Oracle;
class Program
{
static void Main()
{
var connectionString = "User Id=myUsername;Password=myPassword;Server=myServer;";
using (var connection = new OracleConnection(connectionString))
{
connection.Open();
using (var command = new OracleCommand("SELECT * FROM myTable", connection))
{
using (OracleDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader["myColumn"].ToString());
}
}
}
}
}
}
using Devart.Data.Oracle;
class Program
{
static void Main()
{
var connectionString = "User Id=myUsername;Password=myPassword;Server=myServer;";
using (var connection = new OracleConnection(connectionString))
{
connection.Open();
using (var command = new OracleCommand("SELECT * FROM myTable", connection))
{
using (OracleDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader["myColumn"].ToString());
}
}
}
}
}
}
Imports Devart.Data.Oracle
Friend Class Program
Shared Sub Main()
Dim connectionString = "User Id=myUsername;Password=myPassword;Server=myServer;"
Using connection = New OracleConnection(connectionString)
connection.Open()
Using command = New OracleCommand("SELECT * FROM myTable", connection)
Using reader As OracleDataReader = command.ExecuteReader()
Do While reader.Read()
Console.WriteLine(reader("myColumn").ToString())
Loop
End Using
End Using
End Using
End Sub
End Class
This code snippet is enhanced with proper connection strings. It selects data from a table. It prints a column value to the console. Replace myUsername, myPassword, myServer, myTable, and myColumn with your actual database details. This is how you perform a basic database operation using C# Devart.Data.Oracle.
One of the standout features of Devart.Data.Oracle, a crucial part of any application architecture, is Direct Mode. This allows your application to work with Oracle databases without Oracle Client. It simplifies deployment. It reduces the application's overall footprint.
var connectionString = "User Id=myUsername; Password=myPassword; Direct=True; Server=myServer;";
using (var connection = new OracleConnection(connectionString))
{
connection.Open();
// Use the connection
}
var connectionString = "User Id=myUsername; Password=myPassword; Direct=True; Server=myServer;";
using (var connection = new OracleConnection(connectionString))
{
connection.Open();
// Use the connection
}
Dim connectionString = "User Id=myUsername; Password=myPassword; Direct=True; Server=myServer;"
Using connection = New OracleConnection(connectionString)
connection.Open()
' Use the connection
End Using
This example shows how to enable Direct Mode. Add Direct=True to your connection string.
Devart.Data.Oracle enhances Entity Framework (EF) operations. It provides better performance. It supports both EF Core and EF6. It offers a wide range of Oracle-specific features.
// Example assumes EF Core setup
using (var context = new MyDbContext())
{
var data = context.MyEntities.Where(e => e.Property > 0).ToList();
foreach (var item in data)
{
Console.WriteLine(item.Name);
}
}
// Example assumes EF Core setup
using (var context = new MyDbContext())
{
var data = context.MyEntities.Where(e => e.Property > 0).ToList();
foreach (var item in data)
{
Console.WriteLine(item.Name);
}
}
' Example assumes EF Core setup
Using context = New MyDbContext()
Dim data = context.MyEntities.Where(Function(e) e.Property > 0).ToList()
For Each item In data
Console.WriteLine(item.Name)
Next item
End Using
This code fetches data using EF Core. Replace MyDbContext, MyEntities, and Property with your actual context and entity names.
Bulk operations are crucial for high-performance data manipulation. Devart.Data.Oracle offers bulk copy functionality. This is useful for large data transfers.
using (var connection = new OracleConnection(connectionString))
{
connection.Open();
using (var bulkCopy = new OracleBulkCopy(connection))
{
bulkCopy.DestinationTableName = "targetTable";
bulkCopy.WriteToServer(dataTable);
}
}
using (var connection = new OracleConnection(connectionString))
{
connection.Open();
using (var bulkCopy = new OracleBulkCopy(connection))
{
bulkCopy.DestinationTableName = "targetTable";
bulkCopy.WriteToServer(dataTable);
}
}
Using connection = New OracleConnection(connectionString)
connection.Open()
Using bulkCopy = New OracleBulkCopy(connection)
bulkCopy.DestinationTableName = "targetTable"
bulkCopy.WriteToServer(dataTable)
End Using
End Using
This code demonstrates bulk data insertion. Replace targetTable with your destination table name. dataTable should be your data source.
Performance monitoring is built into Devart.Data.Oracle. It allows you to track and optimize database interactions.
using (var connection = new OracleMonitor() { IsActive = true })
{
// Perform database operations
}
using (var connection = new OracleMonitor() { IsActive = true })
{
// Perform database operations
}
Using connection = New OracleMonitor() With {.IsActive = True}
' Perform database operations
End Using
Enable OracleMonitor and set IsActive to true. This starts monitoring your database operations.
LINQ to SQL transforms complex queries into efficient SQL. Devart.Data.Oracle provides optimized LINQ to SQL capabilities. It supports complex queries and transformations.
using (var context = new MyDbContext())
{
var query = from e in context.MyEntities
where e.PropertyName == "Value"
select e;
foreach (var item in query)
{
Console.WriteLine(item.Property);
}
}
using (var context = new MyDbContext())
{
var query = from e in context.MyEntities
where e.PropertyName == "Value"
select e;
foreach (var item in query)
{
Console.WriteLine(item.Property);
}
}
Using context = New MyDbContext()
Dim query = From e In context.MyEntities
Where e.PropertyName = "Value"
Select e
For Each item In query
Console.WriteLine(item.Property)
Next item
End Using
Replace MyDbContext, MyEntities, PropertyName, and Property with your actual context, entity, and property names. This example queries the database using LINQ.
Each of these features enhances your application. They make your work with Oracle databases more efficient. You have direct access, advanced EF support, bulk operations, performance monitoring, and enhanced LINQ to SQL at your disposal.
Learn About IronPDF's Capabilities as a library that serves a simple yet powerful purpose: it allows developers to create, edit, and extract PDF content within their .NET applications. The real charm of IronPDF lies in its ease of use, offering straightforward methods to convert HTML to PDF - a common requirement for reports, invoices, and documentation in web applications.
Imagine you're working on a project where you need to generate a report from data stored in an Oracle database and then present that report as a PDF file. Here's where the combination of IronPDF and Devart.Data.Oracle comes into play. Devart.Data.Oracle is a high-performance ADO.NET provider that gives developers an efficient way to access Oracle databases from .NET applications.
Let's dive into a practical example to illustrate this process. Suppose we have a table named SalesReport in our Oracle database, and we want to generate a PDF report that summarizes this data. First, you'll need to install IronPDF and Devart.Data.Oracle packages via NuGet. This can be done using the NuGet Package Manager or via the Package Manager Console:
Install-Package IronPdf
Install-Package Devart.Data.Oracle
Next, here's how you could write the code to fetch data from the SalesReport table and generate a PDF:
using Devart.Data.Oracle;
using IronPdf;
using System;
class Program
{
static void Main(string[] args)
{
// Connection string to Oracle Database
var oracleConnectionString = "User Id=your_user;Password=your_password;Direct=True;Sid=your_sid;Server=your_server;";
// SQL query to fetch data
var sqlQuery = "SELECT * FROM SalesReport";
// Initialize the Oracle connection
using (var oracleConnection = new OracleConnection(oracleConnectionString))
{
oracleConnection.Open();
// Execute the query
using (var oracleCommand = new OracleCommand(sqlQuery, oracleConnection))
{
using (var reader = oracleCommand.ExecuteReader())
{
// Here you would normally process your data. For simplicity, let's assume it's just a string of HTML.
var htmlContent = "<h1>Sales Report</h1><p>Generated on " + DateTime.Now + "</p>";
while (reader.Read())
{
// Append data from the reader to the HTML content
htmlContent += $"<p>{reader["ItemName"]} - {reader["SaleAmount"]}</p>";
}
// Now, let's create a PDF from the HTML content
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Save the PDF to a file
pdf.SaveAs("SalesReport.pdf");
}
}
}
Console.WriteLine("PDF generated successfully.");
}
}
using Devart.Data.Oracle;
using IronPdf;
using System;
class Program
{
static void Main(string[] args)
{
// Connection string to Oracle Database
var oracleConnectionString = "User Id=your_user;Password=your_password;Direct=True;Sid=your_sid;Server=your_server;";
// SQL query to fetch data
var sqlQuery = "SELECT * FROM SalesReport";
// Initialize the Oracle connection
using (var oracleConnection = new OracleConnection(oracleConnectionString))
{
oracleConnection.Open();
// Execute the query
using (var oracleCommand = new OracleCommand(sqlQuery, oracleConnection))
{
using (var reader = oracleCommand.ExecuteReader())
{
// Here you would normally process your data. For simplicity, let's assume it's just a string of HTML.
var htmlContent = "<h1>Sales Report</h1><p>Generated on " + DateTime.Now + "</p>";
while (reader.Read())
{
// Append data from the reader to the HTML content
htmlContent += $"<p>{reader["ItemName"]} - {reader["SaleAmount"]}</p>";
}
// Now, let's create a PDF from the HTML content
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Save the PDF to a file
pdf.SaveAs("SalesReport.pdf");
}
}
}
Console.WriteLine("PDF generated successfully.");
}
}
Imports Devart.Data.Oracle
Imports IronPdf
Imports System
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Connection string to Oracle Database
Dim oracleConnectionString = "User Id=your_user;Password=your_password;Direct=True;Sid=your_sid;Server=your_server;"
' SQL query to fetch data
Dim sqlQuery = "SELECT * FROM SalesReport"
' Initialize the Oracle connection
Using oracleConnection As New OracleConnection(oracleConnectionString)
oracleConnection.Open()
' Execute the query
Using oracleCommand As New OracleCommand(sqlQuery, oracleConnection)
Using reader = oracleCommand.ExecuteReader()
' Here you would normally process your data. For simplicity, let's assume it's just a string of HTML.
Dim htmlContent = "<h1>Sales Report</h1><p>Generated on " & DateTime.Now & "</p>"
Do While reader.Read()
' Append data from the reader to the HTML content
htmlContent &= $"<p>{reader("ItemName")} - {reader("SaleAmount")}</p>"
Loop
' Now, let's create a PDF from the HTML content
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
' Save the PDF to a file
pdf.SaveAs("SalesReport.pdf")
End Using
End Using
End Using
Console.WriteLine("PDF generated successfully.")
End Sub
End Class
In this example, we start by setting up a connection to our Oracle database using the Devart.Data.Oracle OracleConnection class. Then, we fetch data from the SalesReport table using a simple SQL query. For the sake of demonstration, the data fetched is transformed into an HTML string (in a real-world scenario, you'd build up a more complex HTML document based on your data). Finally, we use IronPDF's ChromePdfRenderer class to convert the HTML string into a PDF document, which is then saved locally.
In wrapping up this tutorial, it's clear that the integration of Entity Framework Core with Devart.Data.Oracle enriches the development of Oracle-based applications. The fusion of these technologies in your development environment, guided through Visual Studio, opens the door to a lot of possibilities for creating robust, scalable applications. For developers aiming to dive deeper into Oracle-based database applications, leveraging the comprehensive features of Entity Framework Core alongside DotConnect for Oracle provides a solid foundation. You can try IronPDF with a free demo or review pricing that starts from $749.
9 .NET API products for your office documents