C#/Oracle: Connect

回眸只為那壹抹淺笑 提交于 2019-12-24 09:43:44

问题


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?


回答1:


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

This could also be an interesting read for you




回答2:


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.

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.

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

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.




回答4:


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.

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




回答5:


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


来源:https://stackoverflow.com/questions/6546001/c-oracle-connect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!