System.Data.OracleClient requires Oracle client so

2020-03-30 05:21发布

问题:

I have installed Oracle client version 10g on my PC(Registry ORACLE_BASE-D:\oracle\product\10.2.0). I have added below references. System.Data.OracleClient.

I am getting above mentioned error. Below is the Code Snippet .

public static OracleConnection getConnection() 
{

    try 
    {
        dataSource = new SqlDataSource();
        dataSource.ConnectionString = System.Configuration.ConfigurationManager.AppSettings.Get("conn");
        OracleConnection connection = new OracleConnection();
        if (dataSource == null) 
        {
            // Error during initialization of InitialContext or Datasource
            throw new Exception("###### Fatal Exception ###### - DataSource is not initialized.Pls check the stdout/logs.");
        } 
        else
        {
            connection.ConnectionString = dataSource.ConnectionString;
            connection.Open();
        }
        return connection;            
    }catch (Exception ex) 
    {
        throw ex;
    }  

}

Please let me know what are the areas of Concern and where Iam missing.I am new for the combination of Oracle and Asp.Net.

回答1:

It looks like you are using the Microsoft oracle client. I suggest that you use the ODP.net driver as it is much more reliable. (I believe the Microsoft client is being deprecated also?)

http://www.oracle.com/technetwork/topics/dotnet/index-085163.html

Install the ODP.net driver, add a reference to Oracle.DataAccess in your project, and you are good to go! Example code (from my previous post):

using System;
using System.Data;
using Oracle.DataAccess.Client;

static class Program
{
    [STAThread]
    static void Main()
    {
        TestOracle();
    }

    private static void TestOracle()
    {
        string connString = 
            "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)" + 
            "(HOST=servername)(PORT=‌​1521)))" +
            "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=servicename)));"+ 
            "User Id=username;Password=********;";
        using (OracleConnection conn = new OracleConnection(connString))
        {
            string sqlSelect = "SELECT * FROM TEST_TABLE";
            using (OracleDataAdapter da = new OracleDataAdapter(sqlSelect, conn))
            {
                var table = new DataTable();
                da.Fill(table);

                if (table.Rows.Count > 1) 
                    Console.WriteLine("Successfully read oracle.");
            }
        }
    }
}

EDIT: I also encountered the "requires Oracle client software version 8.1.7 or greater" error before. I was caused by installing the Oracle Client onto my computer. You may try uninstalling the Oracle Client (ironically) from your computer if you are set on using the Microsoft driver.



回答2:

Basically in this case, System.Data.OracleClient need access to some of the oracle dll which are not part of .Net. Solutions:

  • Install Oracle Client , and add Oracle client bin location to Path environment varaible of windows OR
  • Copy oraociicus10.dll (Basic-Lite version) or aociei10.dll (Basic version), oci.dll, orannzsbb10.dll and oraocci10.dll from oracle client installable folder to bin folder of application so that application is able to find required dll


回答3:

"I have installed Oracle client version 10g on my PC" "System.Data.OracleClient requires Oracle client software version 8.1.7 or greater"

You are using Microsoft Oracle Client and the types in System.Data.OracleClient are depreciated in .NET Framework 4.0 and will be removed from future versions of .NET http://msdn.microsoft.com/en-us/library/77d8yct7.aspx

Check if you still have older Oracle Clients (8 or lower) on your computer. The PATH variable probably still points to the older Oracle client bin directory. If you run 'tnsping' from windows command line, and if you don't see the version 10, then it's still defaulted to the older.

Before you install newer Oracle Clients, it's always a good idea to first uninstall all existing oracle clients. And then install the highest version of oracle client supported by your Oracle Database server and your organization.

You may want to try Oracle Client 11g R2 and install the Oracle Data Providers for .NET http://www.oracle.com/technetwork/topics/dotnet/index-085163.html

If you are using .NET Framework 4.0 or higher, when you add reference to the Oracle.DataAccess in the Visual Studio Project, make sure that this dll is of 4.x.x.x, otherwise browse to your client location and pick the 4.x.x.x dll



回答4:

The Oracle client software still needs to be installed on the client computer to allow connection to the Oracle database. The database user the SQL*Net which is the Oracle connectivity layer for Oracle database. The System.Data.OracleClient dll does not provide this function.

Download Oracle client software

You also must include a reference to the DLL when you compile your code. For example, if you are compiling a C# program, your command line should include:

like as:- csc /r:System.Data.OracleClient.dll

MSDN