Within a .netCore library I want to connect to an Oracle database. Is there any way I can do that yet?
I have tried the suggestions on another SO post, but it doesn't work, perhaps removed since? As you can see in my project.json, I'm trying to use "net461".
I'm currently trying using Oracle.ManagedDataAccess.Client via old fashioned ADO.Net. I also know that Oracle haven't bought out a .netCore connector yet. But even there I can't get it to work, it struggles to get the System.Data included, it errors whenever I try to add it.
My project.json looks like this:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Oracle.ManagedDataAccess": "12.1.24160719",
},
"frameworks": {
"netstandard1.6": {
"imports": [
"dnxcore50",
"net461"
]
}
}
}
This is how I was trying to do it at the moment.
using Oracle.ManagedDataAccess.Client;
public class MyRepository
{
public string GetServerVersion()
{
var _db = new OracleConnection("User Id=myUser;Password=myPassword;Data Source=MyOracleConnection");
var serverVersion = _db.ServerVersion;
return serverVersion;
}
}
However the above doesn't compile as it doesn't have System.Data, which I'm struggling to import.
I'm not entrenched on any particular way of doing it, I just want the best reasonable option at this point in time.
Oracle published the official Data Provider for .NET Core on nuget.
Here is a basic example to show how to use it:
using Oracle.ManagedDataAccess.Client;
public void Execute(string queryString, string connectionString)
{
using (OracleConnection connection = new OracleConnection(connectionString))
{
OracleCommand command = new OracleCommand(queryString, connection);
command.Connection.Open();
command.ExecuteNonQuery();
}
}
Basically you can use it exactly like the official .NET System.Data.SqlClient (easy to find online tutorials for this) and just replace everywhere in the code SqlConnection with OracleConnection and SqlCommand with OracleCommand.