我正在将实体框架与 Oracle 提供程序 (Oracle.ManagedDataAccessDTC) 一起使用
从 Visual Studio 运行一切正常,但是当我将其发布到 IIS 时,我收到连接错误异常。
这是我的 webconfig 女巫在 Visual Studio 上运行得很好:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="Entities" connectionString="metadata=res://*/Model.Model.csdl|
res://*/Model.Model.ssdl|
res://*/Model.Model.msl;
provider=Oracle.ManagedDataAccess.Client;
provider connection string='DATA SOURCE=ORCL;PASSWORD=giovanni;USER ID=DB_ES'" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
这是我在 IIS 上遇到的错误:
Server Error in '/EA' Application.
ORA-12154: TNS:não foi possível resolver o identificador de conexão especificado
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: OracleInternal.Network.NetworkException: ORA-12154 could not resolve the connect identifier specified
Source Error:
Line 24: public List<CADASTRO> GetCadastroBy(string CPF, string Cartao)
Line 25: {
Line 26: return ent.CADASTRO.Where(x => x.CPF.Equals(CPF) && x.NUMEROSEUCARTAO.Equals(Cartao)).Select(x => x).ToList<CADASTRO>();
Line 27: }
sql plus 的查询工作正常。
有什么想法吗?
解决方案:
<oracle.manageddataaccess.client>
<version number="4.121.1.0">
<settings>
<setting name="TNS_ADMIN" value="C:\app\giovanni.saraiva\product\11.2.0\dbhome_2\network\admin"/>
</settings>
</version>
</oracle.manageddataaccess.client>
在网络配置上。
托管驱动程序似乎无法解析 TNS 名称。
您应该确保您的配置正确(请参阅文档).
例如:
<oracle.manageddataaccess.client>
...
<settings>
...
<setting name="TNS_ADMIN" value="C:\path\where\TNSNAMESFILE\is"/>
...
</settings>
...
</oracle.manageddataaccess.client>
另外,如果尚未在中定义,您可能需要配置提供程序工厂machine.config
:
<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.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
顺便说一句,我注意到您提到 Oracle.ManagedDataAccessDTC 作为托管驱动程序。请注意,Oracle.ManagedDataAccessDTC 实际上是提供分布式事务支持的组件,而主驱动程序集称为“Oracle.ManagedDataAccess”。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)