C#/Oracle:连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6546001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:05:58  来源:igfitidea点击:

C#/Oracle: Connect

c#oracleoracle10gdatabase-connection

提问by Eike Cochu

i've been trying to find out how to connect a c# program with an oracle 10g db. all code examples i found always used either ado.net oracleclient of .net-framework (which is deprecated -> not good), or system.data.ado, which apparently uses a data source (odbc) -> not allowed to use, or the oracle developer tools odt (like odbc?), which support olny visual studio 2005 for 10g and only 11g for vs 2010... is there any way to connect, like it is possible with delphi (devart, odac), which ive used before i was told to look into the possibilities of connecting c# and oracle?

我一直在尝试找出如何将 ac# 程序与 oracle 10g db 连接起来。我发现的所有代码示例总是使用 .net-framework 的 ado.net oracleclient(已弃用 -> 不好),或 system.data.ado,它显然使用数据源 (odbc) -> 不允许使用,或 oracle 开发人员工具 odt(如 odbc?),它支持 olny Visual Studio 2005 10g 和仅 11g 的 vs 2010 ......在我被告知研究连接 c# 和 oracle 的可能性之前使用过吗?

回答by V4Vendetta

I think the best way would be to use ODP.NETto perform your actions on oracle database.

我认为最好的方法是使用ODP.NET在 oracle 数据库上执行您的操作。

This could also be an interesting readfor you

这对你来说也可能是一个有趣的阅读

回答by Filburt

The simplest way would be to use System.Data.OleDbwhich should work fine for any version of Visual Studio and the .Net Framework - unless you need to perform any Oracle-specific queries that are not supported on OleDb.

最简单的方法是使用System.Data.OleDbwhich 应该适用于任何版本的 Visual Studio 和 .Net Framework - 除非您需要执行 OleDb 不支持的任何特定于 Oracle 的查询。

A big bonus imho is that you won't have to deal with deploying any special 3rd party database driver.

恕我直言,一个很大的好处是您不必处理部署任何特殊的 3rd 方数据库驱动程序。

回答by Guffa

On connectionstrings.com/oracleyou can find several examples of connection string for several providers.

connectionstrings.com/oracle 上,您可以找到多个提供程序的连接字符串示例。

I would recommend something like ODP.NET or OracleClient that uses the native interface to the database.

我会推荐像 ODP.NET 或 OracleClient 这样的使用数据库本地接口的东西。

The data classes are very similar between different databases, so you can just take an example that uses SqlClientclasses (example) and substitute OracleClientclasses, and change the connection string.

不同数据库之间的数据类非常相似,因此您可以仅举一个使用SqlClient类(example)和替代OracleClient类的示例,并更改连接字符串。

回答by Thiib

See the following code ;)

请参阅以下代码;)

using System;
using System.Data;
using System.Data.OleDb;

class OleDbConnectionOracle
{
  public static void Main()
  {
    string connectionString = "provider=MSDAORA;data source=ORCL;user id=SCOTT;password=TIGER";
    OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);

    OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();

    myOleDbCommand.CommandText = "SELECT empno, ename, sal FROM emp WHERE empno = 7369";

    myOleDbConnection.Open();

    OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();

    myOleDbDataReader.Read();

    myOleDbDataReader.Close();
    myOleDbConnection.Close();
  }
}

回答by BMG

It took very long time to realize my mistake, I was trying to migrate dotnet application from X86 to X64 with oracle data access dependencies.

我花了很长时间才意识到我的错误,我试图将 dotnet 应用程序从 X86 迁移到具有 oracle 数据访问依赖项的 X64。

The oracle connection problem had just gone by moving from OracleConnection to OleDbConnection works well Thanks!.

oracle 连接问题刚刚通过从 OracleConnection 移动到 OleDbConnection 工作良好谢谢!