Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9393312
  • 博文数量: 1747
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 20060
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1747)

文章存档

2024年(23)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: Windows平台

2016-10-20 21:47:23

先安装 VS2013
安装 Oracle12C, 设置环境变量
TNS_ADMIN=D:\Oracle12c\product\12.1.0\dbhome\NETWORK\ADMIN
ORACLE_HOME=D:\Oracle12c\product\12.1.0\dbhome

安装 ODTforVS2013_121025.exe

用VS2013进行Oracle服务器测试的是经常错误, 例如找不到tns_names.ora 或者can not load type OracleInternal.comm等等.
主要是因为冲突. here is a conflict between Oracle.ManagedDataAccess from NuGet and the one that is installed (by Oracle client installation) on a server and that is registered in GAC. 解决的办法就是Unregister Oracle.ManagedDataAccess from GAC and you will get rid of the error: Run command line and navigate to the directory:

方式一: 用管理员执行

点击(此处)折叠或打开

  1. C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64>gacutil.exe /u Oracle.ManagedDataAccess
  2. Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.33440
  3. 版权所有(C) Microsoft Corporation。保留所有权利。


  4. 程序集: Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL
  5. 已卸载: Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL
  6. 卸载的程序集数 = 1
  7. 失败次数 = 0
方式二. 

点击(此处)折叠或打开

  1. //Run command line and navigate to the directory:

  2. //{Oracle home}\product\{version}\client_64\ODP.NET\managed\x64
  3. //There you should find OraProvCfg.exe file. Run the following command to unregister Oracle.ManagedDataAccess from GAC:

  4. OraProvCfg /action:ungac /providerPath:Oracle.ManagedDataAccess




做个程序测试一下

点击(此处)折叠或打开

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;

  10. using Oracle.DataAccess.Client;

  11. namespace WindowsFormsApplication1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }

  19.         private void button1_Click(object sender, EventArgs e)
  20.         {
  21.             string connectionString;
  22.             string queryString;

  23.             //链接字符串
  24.             connectionString = "DATA SOURCE=10.0.0.2/Patrol;PERSIST SECURITY INFO=True;USER ID=xxx; password=yyyy";
  25.             queryString = "select * from tbl_demo";

  26.             OracleConnection myConnetion = new OracleConnection(connectionString);
  27.             OracleCommand myOraCommand = myConnetion.CreateCommand();
  28.             myOraCommand.CommandText = queryString;
  29.             try
  30.             {
  31.                 myConnetion.Open();
  32.             }
  33.             catch (Exception err)
  34.             {
  35.                 this.Text = err.Message;
  36.             }
  37.             OracleDataAdapter oraDA = new OracleDataAdapter(myOraCommand);
  38.             DataSet ds = new DataSet();
  39.             oraDA.Fill(ds);
  40.             myConnetion.Close();
  41.             DataTable dt = ds.Tables[0];
  42.             this.dataGridView1.DataSource = dt;
  43.         }
  44.     }
  45. }
切记引入 Oracle.DataAccess, 编译的时候用 x64 的平台.

asp.net 的样例

点击(此处)折叠或打开

  1. <configSections>
  2.     <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  3.     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  4.     <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
  5.   </configSections>

  6. <oracle.manageddataaccess.client>
  7.     <version number="*">
  8.       <dataSources>
  9.         <dataSource alias="PVMDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=pdxcludds108.pacificorp.us)(PORT=11086))(CONNECT_DATA=(SERVICE_NAME=DDS1086.PACIFICORP.US))) " />
  10.       </dataSources>
  11.     </version>
  12.   </oracle.manageddataaccess.client>
  13.   <connectionStrings>
  14.     <add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=USERID;Password=WORKINGPASSWORD;Data Source=PVMDataSource" />
  15.     <add name="PVMEntities" connectionString="metadata=res://*/Models.PVMModel.csdl|res://*/Models.PVMModel.ssdl|res://*/Models.PVMModel.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string="DATA SOURCE=pdxcludds108.pacificorp.us:11086/DDS1086.PACIFICORP.US;PASSWORD=XXXXXXX;PERSIST SECURITY INFO=True;USER ID=XXX"" providerName="System.Data.EntityClient" />
  16.   </connectionStrings>


阅读(2238) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~