从 .NET 连接到 Oracle 10g
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2474798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connecting to Oracle 10g from .NET
提问by Xinus
I am trying to connect to oracle server located at some IP address but always get error as
我正在尝试连接到位于某个 IP 地址的 oracle 服务器,但总是出现错误
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:line 26
System.TypeInitializationException:“Oracle.DataAccess.Client.OracleConnection”的类型初始值设定项引发异常。---> Oracle.DataAccess.Client.OracleException 提供程序与 Oracle.DataAccess.Client.OracleInit.Initialize() 处 Oracle.DataAccess.Client.OracleConnection..cctor() 处的 Oracle 客户端版本不兼容 ---内部异常堆栈跟踪结束 --- 在 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:line 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 clientand oracle 10gR2 providerfor ASP.NET under Windows Vista. Am I missing anything ?
我已经在Windows Vista下为 ASP.NET安装了oracle 10gR2 客户端和oracle 10gR2 提供程序。我错过了什么吗?
Problem Partially solved I had installed oracle client after provider
问题部分解决我在provider之后安装了oracle客户端
..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
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(Int32errCode) , 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
采纳答案by Xinus
Problem solved ... windows vista security (?) was the problem I ran the program as administrator and everything worked fine
问题解决了... windows vista security (?) 是问题我以管理员身份运行程序,一切正常
回答by itowlson
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.
您的 Oracle.DataAccess.dll 版本似乎与您的 Oracle 客户端安装不同步。例如,您可能正在使用需要 Oracle 11 客户端的最新版本的 Oracle.DataAccess.dll。
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).
检查 Oracle.DataAccess.dll 的版本字符串。我相信 Oracle 10 DLL 的版本为“10.xyz”,而 Oracle 11 DLL 的版本为“2.xyz”(是的,令人困惑)。
Note that this is nota server versioning issue -- this error is happening as the OracleConnection class tries to initialise itself, long before it gets to talk to a server.
请注意,这不是服务器版本控制问题——该错误发生在 OracleConnection 类尝试初始化自身时,早在它与服务器对话之前。
回答by Bob
You can try seeing if ASP.NET has permissions on the Oracle folder, that may be the cause of your situation
您可以尝试查看 ASP.NET 是否对 Oracle 文件夹具有权限,这可能是您情况的原因