简体   繁体   English

从asp.net核心连接到Oracle数据库

[英]Connect to Oracle database from asp.net core

First off I have read other posts about connecting to an Oracle database, unfortunately they could not help me. 首先,我已经阅读了有关连接到Oracle数据库的其他帖子,遗憾的是他们无法帮助我。 I'll describe what I have tried and hopefully someone can point me in the correct direction. 我将描述我所尝试的内容,并希望有人可以指出我正确的方向。

First off I tried to install ODTwithODAC122010 as many sources are saying,but this one gives me a few process exited with non zero exit code. 首先我尝试安装ODTwithODAC122010,正如许多消息来源所说的那样,但是这个给了我一些退出非零退出代码的过程。 It says it's successful but nothing seems to be changed. 它说它很成功,但似乎没有任何改变。

Next to that I tried installing ODTforVS2017_122010.exe I have an updated Visual Studio professional. 在我旁边尝试安装ODTforVS2017_122010.exe我有一个更新的Visual Studio专业人员。 It says the installation is a success. 它说安装是成功的。 This however does not seems to add any option like tutorials describe. 然而,这似乎没有像教程描述那样添加任何选项。 With this I mean that there should be something visible in; 有了这个,我的意思是应该有一些可见的东西;

visual studio tools -> connect to database -> Oracle database, data provider menu should have something like Oracle for.. This doesn't show up unfortunately.. visual studio工具 - >连接到数据库 - > Oracle数据库,数据提供者菜单应该有类似Oracle的东西..这不显示不幸...

So I tried connecting to the database in my visual studio project selecting the .net framework data provider for oracle. 所以我尝试连接到我的visual studio项目中的数据库,为oracle选择.net框架数据提供程序。 Here three fields are asked: Server name username and password. 这里要求三个字段:服务器名称用户名和密码。 I tried filling them in but it couldn't connect. 我尝试填写它们但它无法连接。 For server name I used: IPADDRESS:PORT/SERVICENAME 对于我使用的服务器名称:IPADDRESS:PORT / SERVICENAME

After that I gave up hope for connecting to the database through visual studio (I can connect to the database using oracle SQL developer). 之后,我放弃了通过visual studio连接到数据库的希望(我可以使用oracle SQL开发人员连接到数据库)。

Then I installing the following nuget packages: - Oracle.ManagedDataAccess - System.Configuration.ConfigurationManager - System.Security.Permissions - System.Security.Principal 然后我安装以下nuget包: - Oracle.ManagedDataAccess - System.Configuration.ConfigurationManager - System.Security.Permissions - System.Security.Principal

And wrote a piece of code to connect to the database like: 并写了一段代码连接到数据库,如:

using(OracleConnection connect = new OracleConnection(ConnectionDetails.returnConnectionString()))
{
    connect.Open();
    Console.WriteLine("did it work?" + connect.ServerVersion);
}

Where returnConnectionString returns: returnConnectionString返回的位置:

"User Id=MYID;Password=MYPASSWORD;Data Source=IPADDRESS:PORT/SERVICENAME"

Unfortunately when I try to run this I'm facing a ExecutionContext.cs not found. 不幸的是,当我尝试运行它时,我面临一个未找到的ExecutionContext.cs。 This is happening at connect.open(); 这发生在connect.open();

I'm launching this code at: 我将在以下位置启动此代码:

    public static void Main(string[] args)
    {
        var a = new DatabaseConnector();
        a.test();
        BuildWebHost(args).Run();
    }

As I final word I want to make it clear that I'm using ASP.NET Core and that your suggestions and help will be greatly appreciated! 最后,我想明确表示我正在使用ASP.NET Core,您的建议和帮助将不胜感激!

To be precise, 确切地说,

  1. Right click on your project 右键单击您的项目
  2. Go to Manage NuGet packages 转到管理NuGet包
  3. Search for Oracle.manageddataaccess.core . 搜索Oracle.manageddataaccess.core。 You will get Nuget package 2.12.0-beta2 version. 您将获得Nuget包2.12.0-beta2版本。 Add it. 添加它。
  4. In the page, import as below to access oracle classes 在页面中,导入如下以访问oracle类

    using Oracle.ManagedDataAccess.Client; 使用Oracle.ManagedDataAccess.Client;

This is a beta version of Oracle data access provider and PROD version is supposed to be available at the end of 3rd quarter of 2018. 这是Oracle数据访问提供商的测试版,PROD版本应该在2018年第三季度末提供。

There's currently no ODP.NET support for .NET Core, it was suppose to be released last year, but there's been no news more than and it's coming tweet from the ODP twitter account a couple of weeks ago. 目前没有针对.NET Core的ODP.NET支持,它假设将在去年发布,但几周之前没有新闻,而且它正在推出来自ODP 推特账户的推文

You can make the current version work by moving your project from .netcoreapp2 to a net461 or higher target framework, but it would remove the cross platform support from your project. 您可以通过将项目从.netcoreapp2移动到net461或更高目标框架来使当前版本工作,但它会从项目中删除跨平台支持。

In order to move your project to .net461 or any other follow this steps: 要将项目移动到.net461或任何其他项目,请按照以下步骤操作:

  1. Edit your csproj file and replace the TargetFramework with net461 编辑csproj文件并用net461替换TargetFramework
  2. If you have a web project then remove the Microsoft.AspNetCore.All package and install the Microsoft.AspNetCore (which should download the others dependencies). 如果您有一个Web项目,则删除Microsoft.AspNetCore.All包并安装Microsoft.AspNetCore (应下载其他依赖项)。

At the time of asking this question there was no driver Roy Sanchez answered that. 在提出这个问题时,没有司机Roy Sanchez回答这个问题。 A few weeks the driver got released on the oracle site and a as a nuget package. 几个星期后,驱动程序在oracle网站上发布,并作为一个nuget包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM