我正在尝试使用 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;
}
}