I programmed an Oracle Database connection to Oracle Express Version 10
It works on my development PC (Windows Vista).
When I run this program on Windows XP PC, the Oracle DB connection throws an exception when connecting to the server
“Error: The type initializer for ‘Oracle.DataAccess.Client.OracleConnection’ threw an exception”
The code for the connection is below:
try{
string oradb = "Data Source="
+"(DESCRIPTION ="
+" (ADDRESS = (PROTOCOL = TCP)(HOST = " + IP + ")(PORT = 1521))"
+" (CONNECT_DATA ="
+" (SERVER = DEDICATED)"
+" (SERVICE_NAME = XE)"
+" )"
+ " );User id=XXXX;Password=XXXX;";
OracleConnection conn = new OracleConnection(oradb);
.....
.....
}
catch (Exception ex)
{
MessageBox.Show("Error:" + ex.Message);
}
Which version of client software on the XP box ?
Checking my computer configuration I only see ODP.Net 1.x on a Oracle 10g install ( for me it was C:\oracle\product\10.2.0\db_home\ODP.NET\bin\1.x ), it’s a .Net 1.0 install that won’t work with .net 2.0 – 4.0. This may be the source of your trouble.
The Oracle 10.2 ODP.Net drivers were also remarkably flaky (even the .Net 2.0 version). If you are using .Net 1.0 or 1.1, you may have to re register Oracle.DataAccess.dll using ODPReg.exe (same directory), if you are using 2.0 you may have to install an .net 2.0 (up to 3.5) Oracle client or a .Net 4.0 (or 4.5) Oracle client.
I would suggest you install a 11.2 client, and check that Oracle.DataAccess.dll is correctly registered ( there are 2 installations : one for .Net 2.0-3.5, one for .Net 4.0, on my box C:\oracle\product\11.2.0\client_ODTwithODAC112030\odp.net\bin\2.x and C:\oracle\product\11.2.0\client_ODTwithODAC112030\odp.net\bin\4 ).
You may need to force registration using OraProvCfg.exe
You may also try using Xcopy driver installation, if you want to distribute the drivers with your software, be sure to read carefully the documentation, it’s bizarre and error prone ( ODAC112030Xcopy_x64.zip for example ).
ODAC is here : http://www.oracle.com/technetwork/developer-tools/visual-studio/downloads/index.html.