C# connection with Oracle: Every one encounter this issue while you tried to get a connection with oracle using .Net Frame work. You Might have Installed a lot of dependencies, 64 bit, 32 bit packages of both oracle client and .Net frame work, IIS resets etc etc.
When i got stuck with these below errors
*"The type or namespace name 'OracleClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)"
*" Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed."
I had done google a lot but no use. Every one are busy with installing the 64 and 32 bit packages. At last Verified its cause & Solution.
I'm explaining it with specifications: 64 bit OS windows 7, 64 bit .Net Framework packages, 64 bit Oracle client Installation packages. With Reference to http://www.codeproject.com/Articles/18692/Instant-Oracle-Using-C . Then you have an Idea about what you are going to achieve. In the above link it says about the c# programming to code and connection, but I faced issue mainly in those two errors. So create a project as like in the above link and proceed to below.
In the above link says "Be sure to include a reference to System.Data.OracleClient.dll, and place the following at the top of your code along with all the other
using statements:" from where you start error with.Solution:
1) You need to include "System.Data.OracleClient.dll" from "C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Data.OracleClient.dll" (Where ever you have installed your .NET framework). By 'Add Reference-> Browse Tab '. But in .NET tab you can't able to find "System.Data.OracleClient.dll".
2) You will get Error when you build as
"The type or namespace name 'OracleClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)"
So you need to change Properties->Application->Target FrameWork
as ".NET framework 4" instead of ".NET framework 4 Client". Then you can see on 'Add Reference' windows in .NET Tab 'System.Data.OracleClient.dll'
3) Then You can build with out errors and run the program, But (a big 'BUT') You will encounter a exception As
" Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed."
Then you need to stop running and change Properties->Build->Platform Target to "Any CPU" instead of x86 or x64.
[To make sure add a reference path "C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Data.OracleClient.dll" (Where ever you have installed your .NET framework). ]
Everything will work fine.
Cheers!
132
ReplyDeletethanks, solution 3 works :)
ReplyDeleteThanks a lot.. I was stuck with this issue since 2 days. I tried all means but could not make any progress. Finally I came across this solution and it worked like wonders :D
ReplyDeleteIt is not working for me.
ReplyDelete