简体   繁体   English

C#/Oracle:连接

[英]C#/Oracle: Connect

i've been trying to find out how to connect a c# program with an oracle 10g db.我一直在尝试找出如何将 c# 程序与 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?我发现的所有代码示例总是使用.net-framework的ado.net oracleclient(已弃用->不好),或system.data.ado,它显然使用数据源(odbc)->不允许使用,或者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我被告知要研究连接 c# 和 oracle 的可能性?

I think the best way would be to use ODP.NET to perform your actions on oracle database.我认为最好的方法是使用ODP.NET在 oracle 数据库上执行您的操作。

This could also be an interesting read for you这对你来说也可能是一个有趣的读物

The simplest way would be to use System.Data.OleDb which 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.OleDb ,它应该适用于任何版本的 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.恕我直言,一个很大的好处是您不必处理部署任何特殊的第 3 方数据库驱动程序。

On connectionstrings.com/oracle you 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 SqlClient classes ( example ) and substitute OracleClient classes, and change the connection string.不同数据库之间的数据类非常相似,因此您可以仅举一个使用SqlClient类(示例)并替换OracleClient类的示例,并更改连接字符串。

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 运行良好谢谢..

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();
  }
}

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

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