So we’ve been doing some development at work with Spring.Net and Sql Server. This has gone very well. Probably due to the fact that all of our development has been within Visual Studio, and SQL Server support is nearly inseparable from the IDE. Enter the task of Oracle integration. Under normal circumstances, this task would not sound so daunting. Install the full client and all of it’s 800+MB glory, reference the DLL from the GAC, and move on with life.
Now imagine a world where the typical end user doesn’t know the difference between Oracle, SQL Server, MySQL, a can of pinto beans….. Now try telling this user they have to install this client in a particular directory, be careful not to upgrade it, or delete this random directory on their machine that doesn’t sit with their program. Okay, I know I’ve detailed the extreme here but I think I’m making my point here. why do I need to install so many binaries on someone’s pc just to get my end client to work?
After searching several forums, I learned there is a lean way to deploy the Oracle solution. The problem I had with a lot of these forum posts was they were not giving all of the details to solve my particular problem.
So let’s get started.
First of all, take note of whether or not you will be using the 32 binaries or the 64 bit. This plays a big part in how your project will be able to be deployed using Visual Studio. If you know for a fact you’re going to be going the 64 bit route, go ahead and bite the bullet now and set your visual studio project to 64 bit. If you’re going the 32 bit route, set your targets to x86. This is going to save you some grief down the road of relying on Visual Studio’s Any CPU option.
The trick from here now is to grab a certain subset of DLLs. Probably the easiest way to grab these DLLs is to download the Oracle Instant Client ODP.Net installation. Once you have installed this binary set, rename the oracle directory. I know this sounds crazy, but this will help to guarantee you are not accidentally referencing this dll set instead of those you will be placing in your project. (Thank you cryptic WOW64 undocumented registry key for giving me false hope so many times).
Locate the following dlls (where XX is your version number, latest release is 11 and will be about 80MB):
- oci.dll
- ociw32.dll
- Oracle.DataAccess.dll
- orannzsbbXX.dll
- oraocciXX.dll
- oraociicusXX.dll
- OraOpsXXw.dll
Now place a copy of these files in a folder in your project for your own reference. In your project, reference Oracle.DataAccess.dll. This will be the only dll you can reference within your project. You will probably notice that if you build the project, the first item you have accessing Oracle will fail. The next key component is to make sure the rest of the Oracle dlls are getting dumped into the bin folder at build time. Go to the Build Events tab on your Project’s properties page. I place a command line value in there of copy “C:\projectname\OracleLib\*.*” “$(TargetDir)” /y where projectname\oraclelib is where the dlls are stored. Upon a successful build this will move in the files to your bin folder appropriately. This should prove to be successful for most of your thick client solutions. There is still one more pitfall – using this solution in an ASP.Net application. You may find yourself getting a Bad Image error message or Incompatible Oracle Version error. If you are using the 64 bit Oracle dlls, you cannot debug using Visual Studio’s native Cassini web server. This web server is only capable of loading x86 compatible binaries. You will need to develop against a local 64 bit IIS in order to get the appropriate results.
And there you have it, a working much leaner implementation of Oracle with .Net. Enjoy!