Connecting to Oracle 10g from .NET
I am trying to connect to oracle server located at some IP address but always get error as
System.TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception. ---> Oracle.DataAccess.Client.OracleException The provider is not compatible with the version of Oracle client at Oracle.DataAccess.Client.OracleInit.Initialize() at Oracle.DataAccess.Client.OracleConnection..cctor() --- End of inner exception stack trace --- at Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString) at WebApplication1._Default.Page_Load(Object sender, EventArgs e) in C:\Users\Sunil\Documents\Visual Studio 2008\Projects\WebApplication1\WebApplication1\Default.aspx.cs:lin开发者_StackOverflow中文版e 26
Here is a test file
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Oracle.DataAccess.Client;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try {
string oradb = "Data Source=(DESCRIPTION=(ADDRESS_LIST="
+ "(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.11)(PORT=1523)))"
+ "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));"
+ "User Id=<user id>;Password=<some password>;";
OracleConnection conn = new OracleConnection(oradb); // C#
conn.Open();
}
catch (Exception ex){
Label1.Text = ex.ToString();
}
}
}
}
I have installed oracle 10gR2 client and oracle 10gR2 provider for ASP.NET under Windows Vista. Am I missing anything ?
Problem Partially solved I had installed oracle client after provider
..but now exception showing as
Oracle.DataAccess.Client.OracleException at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure) at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src) at Oracle.DataAccess.Client.OracleConnection.Open() at WebApplication1._Default.Page_Load(Object sender, EventArgs e) in C:\Users\Sunil\Documents\Visual Studio 2008\Projects\WebApplication1\WebApplication1\Default.aspx.cs:line 28
Problem solved ... windows vista security (?) was the problem I ran the program as administrator and everything worked fine
It looks like your version of Oracle.DataAccess.dll is out of sync with your Oracle client install. For example, you may be using a recent version of Oracle.DataAccess.dll which requires the Oracle 11 client.
Check the version string of Oracle.DataAccess.dll. I believe that the Oracle 10 DLL is versioned "10.x.y.z" and the Oracle 11 DLL is versioned "2.x.y.z" (yes, it is confusing).
Note that this is not a server versioning issue -- this error is happening as the OracleConnection class tries to initialise itself, long before it gets to talk to a server.
You can try seeing if ASP.NET has permissions on the Oracle folder, that may be the cause of your situation
精彩评论