先安装 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:
方式一: 用管理员执行
-
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64>gacutil.exe /u Oracle.ManagedDataAccess
-
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.33440
-
版权所有(C) Microsoft Corporation。保留所有权利。
-
-
-
程序集: Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL
-
已卸载: Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL
-
卸载的程序集数 = 1
-
失败次数 = 0
方式二.
-
//Run command line and navigate to the directory:
-
-
//{Oracle home}\product\{version}\client_64\ODP.NET\managed\x64
-
//There you should find OraProvCfg.exe file. Run the following command to unregister Oracle.ManagedDataAccess from GAC:
-
-
OraProvCfg /action:ungac /providerPath:Oracle.ManagedDataAccess
做个程序测试一下
-
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Linq;
-
using System.Text;
-
using System.Threading.Tasks;
-
using System.Windows.Forms;
-
-
using Oracle.DataAccess.Client;
-
-
namespace WindowsFormsApplication1
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private void button1_Click(object sender, EventArgs e)
-
{
-
string connectionString;
-
string queryString;
-
-
//链接字符串
-
connectionString = "DATA SOURCE=10.0.0.2/Patrol;PERSIST SECURITY INFO=True;USER ID=xxx; password=yyyy";
-
queryString = "select * from tbl_demo";
-
-
OracleConnection myConnetion = new OracleConnection(connectionString);
-
OracleCommand myOraCommand = myConnetion.CreateCommand();
-
myOraCommand.CommandText = queryString;
-
try
-
{
-
myConnetion.Open();
-
}
-
catch (Exception err)
-
{
-
this.Text = err.Message;
-
}
-
OracleDataAdapter oraDA = new OracleDataAdapter(myOraCommand);
-
DataSet ds = new DataSet();
-
oraDA.Fill(ds);
-
myConnetion.Close();
-
DataTable dt = ds.Tables[0];
-
this.dataGridView1.DataSource = dt;
-
}
-
}
-
}
切记引入 Oracle.DataAccess, 编译的时候用 x64 的平台.
asp.net 的样例
-
<configSections>
-
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
-
<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>
-
-
<oracle.manageddataaccess.client>
-
<version number="*">
-
<dataSources>
-
<dataSource alias="PVMDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=pdxcludds108.pacificorp.us)(PORT=11086))(CONNECT_DATA=(SERVICE_NAME=DDS1086.PACIFICORP.US))) " />
-
</dataSources>
-
</version>
-
</oracle.manageddataaccess.client>
-
<connectionStrings>
-
<add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=USERID;Password=WORKINGPASSWORD;Data Source=PVMDataSource" />
-
<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" />
-
</connectionStrings>
阅读(2241) | 评论(0) | 转发(0) |