在c#中传递Oracle ClientID

本文关键字:Oracle ClientID | 更新日期: 2023-09-27 18:04:46

我试图使用Oracle连接ClientID,但我得到一个错误消息,我只是不知道为什么。你能给我指对的路吗?

cnDB.ConnectionString = OracleDatabase.CnnString();            
            cnDB.Open();
            cnDB.ClientId = "SomeUser";             
            cmd.CommandType = CommandType.Text;
            cmd.CommandText=strSQL;
            cmd.Connection = cnDB;
Error   23  'System.Data.OracleClient.OracleConnection' does not contain
a definition for 'ClientId' and no extension method 'ClientId'
accepting a first argument of type
'System.Data.OracleClient.OracleConnection' could be found (are you
missing a using directive or an assembly reference?)

编辑:看起来像ODP。已经在使用。NET。我正在接管别人的代码,也许你可以告诉我这里有什么问题:

using System;
using System.Data;
using System.Configuration;
using System.Data.OracleClient;
public sealed class OracleDatabase
{
    public static DataTable AllData;
    public const string cnstCnnStrSeparator = ";";
    public static String CnnString()
    {
        System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
        String strKeyVal;
        strKeyVal = ConfigurationManager.ConnectionStrings["SecOracle"].ToString();
        return strKeyVal;
    }
    public static DataTable GetDataTable(string strSQL,bool ConvertToString)
    {
        OracleConnection cnDB = new  OracleConnection();  
        OracleCommand cmd = new OracleCommand();
        DataTable dt = new DataTable();
        OracleDataAdapter da = new OracleDataAdapter();       
        try
        {
            cnDB.ConnectionString = OracleDatabase.CnnString();            
            cnDB.Open();
          //  cnDB.ClientId = "SomeUser";             
            cmd.CommandType = CommandType.Text;
            cmd.CommandText=strSQL;
            cmd.Connection = cnDB;             
            da.SelectCommand = cmd;   
            da.Fill(dt);
            DataTable dt1 = dt.Clone();
            if (ConvertToString)
            {
                for (int j = 0; j < dt1.Columns.Count; j++)
                {
                    dt1.Columns[j].DataType = typeof(string);
                }
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr1 = dt1.NewRow();
                    dt1.Rows.Add(dr1);
                }
                for (int i = 0; i < dt.Rows.Count; i++)
                {

                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        dt1.Rows[i][j] = dt.Rows[i][j].ToString();
                    }
                }
                dt = null;
                AllData = dt1.Copy();
                return dt1;
            }
            else
            {
                dt1 = null;
                AllData = dt.Copy();
                return dt;
            }
        }
        catch (Exception ex)
        {
            return null;
        }
        finally
        {
            cnDB.Close();
        }

    }

    public static OracleDataReader GetDataReader(String SQL)
    {
        OracleCommand cmdQuery;
        OracleDataReader dr;
        String str;
        str = CnnString();
        OracleConnection cnDB = new OracleConnection(str);
        cmdQuery = new OracleCommand();
        try
        {
            cmdQuery.Connection = cnDB;
            cmdQuery.CommandText = SQL;
            cmdQuery.CommandType = System.Data.CommandType.Text;
            cnDB.Open();
            dr = cmdQuery.ExecuteReader(CommandBehavior.CloseConnection);
            return dr;
        }
        catch (Exception ex)
        {
            cnDB.Close();
            return null;
        }
        //'
    }
    public static int Execute(String SQL)
    {
        int lngRecords;
        OracleCommand cmdQuery;
        OracleConnection cnDB = null;
        cmdQuery = new OracleCommand();
        try
        {
            cnDB = new OracleConnection(CnnString());
            cmdQuery.Connection = cnDB;
            cmdQuery.CommandText = SQL;
            cmdQuery.CommandType = System.Data.CommandType.Text;
            cnDB.Open();
            lngRecords = cmdQuery.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            lngRecords = -1;
        }
        finally
        {
            cnDB.Close();
        }
        return lngRecords;
    }


}

在c#中传递Oracle ClientID

我假设您正在使用Microsoft System.Data.OracleClient命名空间,并且正如错误消息所述,没有连接的ClientID属性。

您应该使用Oracle的Oracle数据提供程序,并且从特定版本开始,您可以从OTN讨论论坛的这个线程中读取

ClientID在10.2.0.1中添加到ODP中。是的,你可以使用10.2。x ODP和11克的ODP对9。X数据库(假设这就是你安装它的原因)版).