Reputation: 22270
I have following code to connect to a database using ODP.net:
// connection information removed to protect sensitive information
string host = "******";
string sid = "*****";
string connectDescriptor = string.Format("(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST={0})(PORT=1521))(CONNECT_DATA=(SID={1})))", host, sid);
string username = "*****";
string password = "*****";
string connectionString = string.Format("Data Source={0};User ID={1};Password={2};", connectDescriptor, username, password);
OracleConnection conn = null;
try
{
conn = new OracleConnection(connectionString);
conn.Open();
}
catch (OracleException oraex)
{
MessageBox.Show(oraex.ErrorCode + ": " + oraex.Message);
}
finally
{
conn.Close();
}
Call to Open()
throws an error, and I am unable to figure out much about it. oraex.ErrorCode
is -2147467259
and oraex.Message
is ""
. Trying to access most members of the thrown exception results in a NullReferenceException
.
Also, I can see that the base exception is a System.Runtime.InteropServices.ExternalException
.
What is going on here? Because of the InteropServices
exception I am guessing that it is something to do with COM.
System.Data.OracleClient
. They are OK.Upvotes: 1
Views: 974
Reputation: 320
Sounds like it's something with the oracle client. I've faced similar issues with web projects while the console projects were working just fine. If you installed 64bit ODAC, then uninstall it completely and try with 32bit. Also double check the target platform at Visual Studio is "32bit". If that works, you can search what was wrong with 64 bit installation.
Upvotes: 1