简体   繁体   English

Oracle Instant Client和Entity Framework配置出现问题

[英]Oracle Instant Client and Entity Framework trouble with configuration

I'm trying to learn and figure out if it is possible to deploy an MVC, EF, ODAC 11.2.0.3 app to a server that has a previous version of ODP.NET installed. 我正在尝试学习并弄清楚是否可以将MVC,EF,ODAC 11.2.0.3应用程序部署到已安装ODP.NET早期版本的服务器。 Rather than updating the sever ODP.NET (which I can't), I figured I could use the Oracle Instant Client. 我认为我可以使用Oracle Instant Client,而不是更新服务器ODP.NET(我不能)。

Is this doable? 这可行吗?

1) I added these dlls to my project to support Instant Client 1)我将这些dll添加到我的项目中以支持Instant Client

-Oracle.DataAccess.dll -Oracle.DataAccess.dll

-oci.dll -oci.dll

-ociw32.dll -ociw32.dll

-orannzsbb11.dll -orannzsbb11.dll

-oraociei11.dll -oraociei11.dll

-OraOps11w.dll -OraOps11w.dll

2) Next I updated web.config for the dbProviderFactories 2)接下来,我为dbProviderFactories更新了web.config

   <system.data>
    <DbProviderFactories>
    <add name="Oracle Data Provider for .NET"
    invariant="Oracle.DataAccess.Client"
    description="Oracle Data Provider for .NET"
    type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess,    Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
    </system.data>

3) This (afaik) is how to use the Oracle dll in the bin rathre than the GAC 3)此(afaik)是如何在bin rathre中使用Oracle dll而不是GAC

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342" />
    <publisherPolicy apply="no" />
  </dependentAssembly>
</assemblyBinding>
</runtime>

4) Finally my connectionString 4)最后我的connectionString

    <connectionStrings>
    <add name="Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=Oracle.DataAccess.Client;
provider connection string=&quot;DATA SOURCE=XXX;PASSWORD=XXX;PERSIST SECURITY INFO=True;USER ID=XXX&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

This is the error I receive Unable to find the requested .Net Framework Data Provider. 这是我收到的错误,找不到所需的.Net Framework数据提供程序。 It may not be installed. 它可能没有安装。

I really appreciate any help here. 我非常感谢您的帮助。 I'm rather new and have a lot to learn. 我很新,有很多东西要学。 Thanks in advance. 提前致谢。 cheers 干杯

Add a <remove … /> section in the <DbProviderFactories> element in the web config to remove any existing Oracle provider. 在Web配置的<DbProviderFactories>元素中添加<remove … />部分,以删除任何现有的Oracle提供程序。 (before the <add> ) (在<add>之前)

<remove invariant ="Oracle.DataAccess.Client" />

Here is my Xcopy solution. 这是我的Xcopy解决方案。

I posted it over at 我张贴在

( https://jeremybranham.wordpress.com/2011/04/25/oracle-instant-client-with-odp-net/#comment-181 ) https://jeremybranham.wordpress.com/2011/04/25/oracle-instant-client-with-odp-net/#comment-181

as well. 也一样

But I think I can post my xml without formatting issues here. 但是我想我可以在不格式化问题的情况下发布xml。

Nuget "packages.config" Nuget“ packages.config”

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="CommonServiceLocator" version="1.0" targetFramework="net35" />
  <package id="EnterpriseLibrary.Common" version="5.0.505.0" targetFramework="net35" />
  <package id="EnterpriseLibrary.Data" version="5.0.505.0" targetFramework="net35" />
  <package id="EntLibContrib.Data.OdpNet" version="5.0.505.0" targetFramework="net35" />
  <package id="Unity" version="2.1.505.2" targetFramework="net35" />
  <package id="Unity.Interception" version="2.1.505.2" targetFramework="net35" />
</packages>

app.config app.config

(note the <clear /> tag below. this may or may not be needed, but I figured it was better to clear them out since you don't know what may be in the machine.config file) (请注意下面的<clear />标记。可能需要也可能不需要,但是我认为最好清除它们,因为您不知道machine.config文件中可能包含什么)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>


  <dataConfiguration defaultDatabase="OracleMainConnectionString">
  </dataConfiguration>

  <connectionStrings>

    <add name="OracleMainConnectionString"
         connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyOracleServerName)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=MyServiceName)));User ID=MyUserName;Password=MyPassword;"
      providerName="Oracle.DataAccess.Client" />
  </connectionStrings>

  <appSettings>
    <add key="ExampleKey" value="ExampleValue" />
  </appSettings>

  <system.data>
    <DbProviderFactories>
      <clear />
      <add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description=".Net Framework Data Provider for Oracle" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
      <add name="EntLibContrib.Data.OdpNet" invariant="EntLibContrib.Data.OdpNet" description="EntLibContrib Data OdpNet Provider" type="EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null" />
    </DbProviderFactories>
  </system.data>


</configuration>

I am developing on a x64 Windows 7 machine. 我正在x64 Windows 7计算机上进行开发。

I downloaded: ODAC1120320Xcopy_32bit.zip (from oracle.com) 我下载了:ODAC1120320Xcopy_32bit.zip(来自oracle.com)

Which is the: 哪一个是:

ODAC 11.2 Release 5 (11.2.0.3.20) Download the XCopy version [Released September 11, 2012] ODAC 11.2版本5(11.2.0.3.20)下载XCopy版本[2012年9月11日发布]

I unzipped this zip file. 我解压缩了该zip文件。

I searched and fished out these files: 我搜索并找到了这些文件:

oci.dll Oracle.DataAccess.dll orannzsbb11.dll oraociei11.dll OraOps11w.dll oci.dll Oracle.DataAccess.dll orannzsbb11.dll oraociei11.dll OraOps11w.dll

Note, when there were 2 files of the same name, I took the "bin\\2.x\\" or "odp.net20\\bin" version for my 3.5 Framework need (I'm not on 4.0 yet). 请注意,当有2个同名文件时,出于3.5框架的需要,我采用了“ bin \\ 2.x \\”或“ odp.net20 \\ bin”版本(我尚未安装4.0)。

I took these files, and put them in a subfolder from where my .sln file resides. 我拿了这些文件,并将它们放在我的.sln文件所在的子文件夹中。

.\MySolution.sln
.\MyConsoleApplicationFolder\MyConsoleApp.csproj
.\ThirdPartyReferences\
.\ThirdPartyReferences\Oracle\

I place all the files above in the 我将以上所有文件放在

.\ThirdPartyReferences\Oracle\ 

folder

I used "Add Reference" to add a reference to Oracle.DataAccess.dll to the "MyConsoleApp.csproj" csharp project. 我使用“添加引用”将对Oracle.DataAccess.dll的引用添加到“ MyConsoleApp.csproj” csharp项目中。 (This meant browsing to "..\\ThirdPartyReferences\\Oracle\\" of course) (这当然意味着浏览到“ .. \\ ThirdPartyReferences \\ Oracle \\”)

I used a "Post Build Event" to copy the "extra" (aka, "accessory)" files 我使用“构建后事件”复制“额外”(又名“附件”)文件

My lines in my post build event were: 我在发布后活动中的台词是:

copy $(ProjectDir)..\ThirdPartyReferences\Oracle\oci.dll $(TargetDir)*.*
copy $(ProjectDir)..\ThirdPartyReferences\Oracle\orannzsbb11.dll $(TargetDir)*.*
copy $(ProjectDir)..\ThirdPartyReferences\Oracle\oraociei11.dll $(TargetDir)*.*
copy $(ProjectDir)..\ThirdPartyReferences\Oracle\OraOps11w.dll $(TargetDir)*.*

Note, my post build event replaces the "Copy if Newer" from the URL instructions above. 请注意,我的发布后事件取代了上述网址说明中的“如果更新则复制”。

When I ran my project........I got a few missing dll errors. 当我运行项目时........我遇到了一些丢失的dll错误。

Note: In the assembly that has your calls to the EnterpriseLibrary.Data objects…you'll get “Cannot find Microsoft.Practices.SomethingSomething namespace. 注意:在调用EnterpriseLibrary.Data对象的程序集中,您将得到“找不到Microsoft.Practices.SomethingSomething命名空间。 Just keep adding references to these dll's (that the above package.config will pull down) until the errors go away. 只需继续添加对这些dll的引用(上面的package.config将下拉),直到错误消失。

Like here is a specific one: 就像这里是一个特定的:

"Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."

So (after running Nuget of course, to download all the files) I went and added a reference to: 因此(当然,在运行Nuget之后,要下载所有文件)我添加了对以下内容的引用:

\\packages\\CommonServiceLocator.1.0\\lib\\NET35\\Microsoft.Practices.ServiceLocation.dll \\ packages \\ CommonServiceLocator.1.0 \\ lib \\ NET35 \\ Microsoft.Practices.ServiceLocation.dll

That cleared up the issues. 这就解决了问题。

And my csharp code: (note "select *" is for demo purposes only) 我的csharp代码:(请注意“ select *”仅用于演示目的)

/*
    using System;
    using System.Data;
    using System.Data.Common;
    using Microsoft.Practices.EnterpriseLibrary.Data;
 */
public IDataReader EmployeesGetAll()
{

    IDataReader returnReader = null;

    try
    {

        Database db = DatabaseFactory.CreateDatabase();
        DbCommand dbc = db.GetSqlStringCommand("SELECT * FROM ( SELECT * FROM TEMPLOYEE ) WHERE ROWNUM <= 25");
        returnReader = db.ExecuteReader(dbc);
        return returnReader;

    }

    finally
    {
    }

}

And it worked. 而且有效。

Thank you: 谢谢:

https://jeremybranham.wordpress.com/2011/04/25/oracle-instant-client-with-odp-net/#comment-181 https://jeremybranham.wordpress.com/2011/04/25/oracle-instant-client-with-odp-net/#comment-181

I think this makes ODP.NET an "xcopy" deployment. 我认为这使ODP.NET成为“ xcopy”部署。

I still need to test on a clean machine to be sure. 确保仍然需要在干净的机器上进行测试。

But its the end of the day.............. 但这一天结束了..............

================ ================

Additional Information: 附加信息:

Everything above is correct. 上面的一切都是正确的。 However, I hit a caveat. 但是,我提出了警告。 I was using a "Console Application" to test my code. 我正在使用“控制台应用程序”来测试我的代码。

When you add a new Console Application to visual studio, it DEFAULTS to x86. 当您将新的控制台应用程序添加到Visual Studio时,它默认为x86。

As seen here: 如此处所示:

http://www.xavierdecoster.com/post/2011/02/15/console-application-visual-studio-gotcha-on-x64-os-aspx http://www.xavierdecoster.com/post/2011/02/15/console-application-visual-studio-gotcha-on-x64-os-aspx

EDIT: (Updated link) 编辑:(更新的链接)

http://www.xavierdecoster.com/post/2011/02/15/console-application-visual-studio-gotcha-on-x64-os http://www.xavierdecoster.com/post/2011/02/15/console-application-visual-studio-gotcha-on-x64-os

So when I put all the configuration and code and stuff in a real project (which was set to "Any CPU" on a x64 bit machine)...everything I had done stopped working. 因此,当我将所有配置和代码以及其他东西放入一个真实的项目(在x64位计算机上设置为“任何CPU”)时...我所做的一切都停止了工作。 :< :<

After tweaking a bit........ I found this file on oracle.com ODAC1120320Xcopy_x64.zip I then repeated everything I did above , but searching the unzipped files of this x64 zip file. 稍作调整后.....我在oracle.com上找到了该文件ODAC1120320Xcopy_x64.zip然后我重复了上面的所有操作,但是搜索了该x64 zip文件的解压缩文件。

Everything is working. 一切正常。

But that "x86" default thing with a Console application threw me for a loop. 但是,带有控制台应用程序的“ x86”默认值使我陷入了循环。

It seems from your question that you need to deploy an update to your application and the new version of ODP.net using only xcopy deployment permission. 从您的问题看来,您只需要使用xcopy部署权限就可以将更新部署到应用程序和新版本的ODP.net。

Since your application is being changed, then you shouldn't need the assembly binding changes or DbProviderFactories. 由于您的应用程序正在更改,因此您不需要程序集绑定更改或DbProviderFactories。 Just update the csproj of the class library with your edmx etc to have a reference to the new ODP.net version, eg 只需使用edmx等更新类库的csproj,即可引用新的ODP.net版本,例如

<Reference Include="Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86" />

If you get an issue with your tnsnames.ora, then you would have to do one of the following: a) Add a system environment variable TNS_ADMIN to point to the directory of the tnsnames.ora, or b) Change the connection string to something based on: 如果tnsnames.ora出现问题,则必须执行以下操作之一:a)添加系统环境变量TNS_ADMIN指向tnsnames.ora的目录,或b)将连接字符串更改为某些内容基于:

Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;

c) See if you can put a copy of the tnsnames.ora somewhere else. c)看看是否可以将tnsnames.ora的副本放在其他位置。

I was getting the same error (data provider not found) when deploying ODP.NET via Instant Client. 通过Instant Client部署ODP.NET时遇到相同的错误(找不到数据提供程序)。 The only thing that I needed to do was to add the following to my exe.config file (inside the tag) 我唯一需要做的就是将以下内容添加到我的exe.config文件中(在标记内)

<system.data>
<DbProviderFactories>
<add name="Oracle Data Provider for .NET"
invariant="Oracle.DataAccess.Client"
description="Oracle Data Provider for .NET"
type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess,    Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM