.net 4 添加 oracle.dataaccess,無法加載文件或程序集的Oracle。DataAccess、Version = 4.112.4.0、文化=中立,都89 b483f429c4734...

I have installed oracle 11 g r 2 in the server, and I downloaded ODAC112040Xcopy_64bit and installed the .net components.

我在服務器上安裝了oracle 11g r2,我下載了ODAC112040Xcopy_64bit並安裝了。net組件。

I copied Oracle.DataAccess.dll that exists in this location Oracle_Folder\odp.net\bin\4 to the bin folder inside my Visual Studio project

我復制Oracle.DataAccess。存在於這個位置的dll, Oracle_Folder\odp.net\bin\4到我的Visual Studio項目中的bin文件夾。

When I executed my code, I got this exception:

當我執行我的代碼時,我得到了一個例外:

An unhandled exception of type 'System.BadImageFormatException' occurred in TestOracleConnection.exe

一個未處理的類型系統異常。發生在TestOracleConnection.exe BadImageFormatException”

Additional information: Could not load file or assembly 'Oracle.DataAccess, Version=4.112.4.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format.

附加信息:不能加載文件或程序集的Oracle。DataAccess, Version=4.112.4.0, Culture=中性,PublicKeyToken=89b483f429c47342或它的一個依賴項。嘗試用不正確的格式加載程序。

My code is:

我的代碼是:

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();

}

}

}

}

}

5 个解决方案

#1

3

Okay, I'm going to suggest the following based on my experience with ODP.NET:

好的,我將根據我在odp的經驗提出以下建議:

Your system is attempting to load the 64 bit Oracle DLL, and can't because the application is running in 32 bit mode. Try setting your application to explicitly be 64 Bit. Alternatively, install the 32 bit ODP.Net drivers and see if those work any better.

您的系統正在嘗試加載64位的Oracle DLL,不能因為應用程序以32位模式運行。嘗試將應用程序設置為顯式64位。或者,安裝32位ODP。Net驅動程序,看看這些工作是否更好。

#2

1

Had a similar problem some time ago... Referring to this question here:

以前有過類似的問題……關於這個問題:

Try to set your projects 'Platform target' to 'x86' and not 'Any CPU'.

嘗試將你的項目平台目標設置為“x86”,而不是“任何CPU”。

Hope this helps!

希望這可以幫助!

#3

1

I usually use the NuGet packages for ODP.net, they work fine. You can find them here.

我通常用NuGet包來做ODP.net,它們工作得很好。你可以在這里找到他們。

This is all you need to build your solution, you do not need to install any drivers.

這是您構建解決方案所需的全部內容,您不需要安裝任何驅動程序。

#4

0

Check that target framework of the dll and your project match.The file location you posted shows you took it from Oracle_Folder\odp.net\bin\4 the bin folder for 4 version. Look if there is the req dll in bin\4.5 that maybe what you need. As this exception can also occur if you add dlls to your project whose target framework do not match.

Also, clean your solution before placing the dll in bin folder. :)

檢查dll的目標框架和項目匹配。您所發布的文件位置顯示您從Oracle_Folder\odp.net\bin\4文件夾中獲取了4個版本的文件夾。看看bin\4.5中是否有req dll,這可能是你需要的。如果您將dll添加到目標框架不匹配的項目中,也會出現此異常。另外,在將dll放入bin文件夾之前,請先清理您的解決方案。:)

#5

0

In order to use the Oracle Data Prover for .NET (ODP.NET) Version 4.112.4.0 64bit following conditions must apply:

為了使用。net (ODP.NET)版本的Oracle Data Prover,必須使用以下條件:

Target Framework is 4.0 or higher

目標框架是4.0或更高。

Architecture must be x64 or AnyCPU (in case of an 64bit Windows, which is most likely the case)

架構必須是x64或任何cpu(如果是64位的窗口,很可能是這樣)

An 64-Bit Oracle Client version 11.2 is installed on your PC and on the target machine

一個64位的Oracle客戶端版本11.2安裝在您的PC上和目標機器上。

在這個anser中找到更多的信息:提供者與Oracle客戶端的版本不兼容。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值