zoukankan      html  css  js  c++  java
  • 使用WEBAPI连接到ORACLE配置流程

    1.引用DLL

    Oracle.ManagedDataAccess.dll 

    Oracle.ManagedDataAccess.EntityFramework.dll  

    下载地址:http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html 

    2.修改Web.Config

    <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <!--<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />-->  
      </configSections>
    
      <entityFramework>
        <defaultConnectionFactory type="Oracle.ManagedDataAccess.EntityFramework.OracleConnectionFactory,
    Oracle.ManagedDataAccess.EntityFramework,
    Version=6.121.2.0,
    Culture=neutral,
    PublicKeyToken=89b483f429c47342" />
        <providers>
          <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
         
        </providers>
      </entityFramework>
    
      <system.data>
        <DbProviderFactories>
          <remove invariant="Oracle.ManagedDataAccess.Client" />
          <add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
              type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
        </DbProviderFactories>
      </system.data>

    3.连接字符串配置

    3.1 配置连接字符串方式

    <connectionStrings>
    
        <add name="OraString" connectionString="Data Source= (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = *****)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = ORCL)
        )
      );User ID=*****;Password=*****;Persist Security Info=True" providerName="Oracle.ManagedDataAccess.Client" />
    
      </connectionStrings>

    3.2 使用TNS配置连接(即tnsnames.ora配置文件)

    
    
    <oracle.manageddataaccess.client>
        <version number="*">
          <settings>
            <setting name="配置连接名" value="ora文件路径" />
            <setting name="TraceOption" value="1" />
            <setting name="PerformanceCounters" value="0" />
          </settings>
        </version>
      </oracle.manageddataaccess.client>

    3.3 如果本机安装了oracle,需要检查以下配置字段,如果有修改版本号Version 为当前Oracle.ManagedDataAccess.Client版本。

    <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />

    3.遇到的问题

    故障:ORA-01918: 用户 'dbo' 不存在

    原因:EF Provider未切换到换成支持Oracle

    解决方法:在上下文里重载OnModelCreating

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                modelBuilder.HasDefaultSchema("这里写你的Oracle用户名,一定要大写噢!");
            }
    位置:上下文一般为:“ 应用名.cs ”, 特征为继承了: DbContext类,可以Ctrl+F全局搜索“: DbContext”找到具体位置。

    注意事项:完成后,需要重新使用Enable-Migrations重新刷新一下edmx。

    有关转载原文以及推荐:

    https://www.cnblogs.com/wlflovenet/p/4187455.html

    http://www.bubuko.com/infodetail-2002598.html

  • 相关阅读:
    Verilog 浮点数运算模块
    【MATLAB】设定坐标的轴的范围
    【MATLAB】画平行于坐标轴的曲线
    【Quartus警告】created implicit net for XXX.
    多普勒雷达探测原理
    高斯分布和均匀分布之间的映射关系
    反射设置当前窗体所有控件的Text
    IAR6.1的工程迁移到IAR6.5不能用的解决方法
    C语言实现通用链表初步(二)
    C语言实现通用链表初步(一)
  • 原文地址:https://www.cnblogs.com/magicalconch/p/14457576.html
Copyright © 2011-2022 走看看