从 ASP.NET 连接甲骨文 11g



如何连接到我的Oracle 11g release 11.2.0.1.0

我的.Net framework is 4 . 我的操作系统是windows 7 64 bit版本。

我从谷歌阅读了一些样本并进行了测试,但它不起作用。

这是我的代码。我用了VS2012 Express 2012 for Web.

我使用了Oracle.DataAccess。任何示例代码或说明帮助不胜感激。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Oracle.DataAccess.Client;
    namespace WebApplication1
    {
        public partial class index : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                OracleConnection connection = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=mySid)));User Id=xxx;Password=xxx;");
                try
                {
                    connection.Open();
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
        }
} 

这是我的错误。

Server Error in '/' Application.
The provider is not compatible with the version of Oracle client
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client
Source Error: 

Line 13:         protected void Page_Load(object sender, EventArgs e)
Line 14:         {
Line 15:             OracleConnection connection = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx)(PORT=xxxx)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xxx)));User Id=xxx;Password=xxxx;");
Line 16:             try
Line 17:             {
Source File: c:PLanguagesPSourcesC#WebApplication1WebApplication1index.aspx.cs    Line: 15 
Stack Trace: 

[OracleException (0x80004005): The provider is not compatible with the version of Oracle client]
   Oracle.DataAccess.Client.OracleInit.Initialize() +624
   Oracle.DataAccess.Client.OracleConnection..cctor() +903
[TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.]
   Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString) +0
   WebApplication1.index.Page_Load(Object sender, EventArgs e) in c:PLanguagesPSourcesC#WebApplication1WebApplication1index.aspx.cs:15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

我在这里找到了答案。

只需要覆盖我的环境变量,我可以轻松连接。

使用 oracle

odp.net 连接到 oracle 数据库,你会没事的。

我的建议是安装软件包odp.net.x64.,你要做的是转到工具,Libery包管理器,包管理器控制台并输入以下内容安装包 odp.net.x64

下面的链接解决了我的问题。

https://www.codeproject.com/Questions/617272/The-provider-is-not-compatible-with-the-version-of

1(检查您是否正在编译为x86或任何CPU(首选任何CPU( 因为它可以在 64 位和 32 位上运行,并且您的 ASMX 可能是 64 位 这正在起作用(。

2( 检查在项目中生成的 .net 版本。

最新更新