我在服务器上安装了Oracle 11g r2,并下载了ODAC112040Xcopy_64bit并安装了.net组件。
我将位于Oracle_Folder\odp.net\bin\4位置的Oracle.DataAccess.dll复制到Visual Studio项目内的bin文件夹中。
当我执行代码时,出现了以下异常:
未处理的System.BadImageFormatException类型异常发生于TestOracleConnection.exe中。
附加信息:无法加载文件或程序集“Oracle.DataAccess,Version=4.112.4.0,Culture=neutral,PublicKeyToken=89b483f429c47342”或其依赖项之一。尝试加载格式不正确的程序。
我的代码如下:
我将位于Oracle_Folder\odp.net\bin\4位置的Oracle.DataAccess.dll复制到Visual Studio项目内的bin文件夹中。
当我执行代码时,出现了以下异常:
未处理的System.BadImageFormatException类型异常发生于TestOracleConnection.exe中。
附加信息:无法加载文件或程序集“Oracle.DataAccess,Version=4.112.4.0,Culture=neutral,PublicKeyToken=89b483f429c47342”或其依赖项之一。尝试加载格式不正确的程序。
我的代码如下:
public string CallCardDetails(string CallCardNo)
{
//initialize
using (DataSet ds = new DataSet())
{
//connect
using (OracleConnection conn = new OracleConnection("User Id=oraDB;Password=ora;Data Source=CCT"))
{
// Oracle uses : for parameters, not @
string query = "SELECT idcard from CallCardTable where idcard= :pCallCardNo";
// Let the using block dispose of your OracleCommand
using (OracleCommand cmd = new OracleCommand(query, conn))
{
// Note: be careful with AddWithValue: if there's a mismatch between the .NET datatype of
// CallCardNo and the idcard column you could have an issue. Cast the value you provide
// here to whatever is closest to your database type (String for VARCHAR2, DateTime for DATE, Decimal for NUMBER, etc.)
cmd.Parameters.Add(":pCallCardNo", CallCardNo);
conn.Open();
// Again, wrap disposables in a using or use try/catch/finally (using will dispose of things in case of exceptions too)
using (OracleDataAdapter dA = new OracleDataAdapter(cmd))
{
dA.Fill(ds);
return ds.GetXml();
}
}
}
}
}
2
和4
(以及Oracle 11.1之前的1.x
)。针对目标框架4.5的应用程序将使用4
。 - Wernfried Domscheit