【发布时间】:2015-06-02 16:23:08
【问题描述】:
我已经在服务器上安装了oracle 11 g r 2,我下载了ODAC112040Xcopy_64bit并安装了.net组件。
我将存在于该位置Oracle_Folder\odp.net\bin\4 中的Oracle.DataAccess.dll 复制到我的Visual Studio 项目中的bin 文件夹中
当我执行我的代码时,我得到了这个异常:
TestOracleConnection.exe 中出现“System.BadImageFormatException”类型的未处理异常
其他信息:无法加载文件或程序集“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();
}
}
}
}
}
【问题讨论】:
-
你的项目是什么 .net 版本?
-
@SyedOsamaMaruf 它是 4.5
Target Framework你在找什么? -
是的。您发布的文件位置显示您从 Oracle_Folder\odp.net\bin\4 4 版本的 bin 文件夹中获取它。看看 bin\4.5 中是否有你需要的 req dll。
-
@SyedOsamaMaruf,不,只有
2和4(以及1.x直到 Oracle 11.1)。 Target Framework 4.5 的应用程序将使用4 -
@Wernfried 谢谢。不知道