我已经使用 DevArt 的提供程序针对 Oracle 数据库设置了 Entity Framework 4.3。我在通过 NUnit 2.6 测试运行程序中的单元测试项目连接到数据库时遇到问题。有趣的是,我有一个 ASP.NET MVC 3 项目连接到它,效果很好。我在类库单元测试项目中创建了一个 App.config 并将实体连接字符串信息复制到其中。我错过了什么?
这是实体连接信息(Web.config 和 App.config 中相同):
<connectionStrings>
<add name="Entities" connectionString="metadata=res://*/Entities.MagellanDataModel.csdl|res://*/Entities.MagellanDataModel.ssdl|res://*/Entities.MagellanDataModel.msl;provider=Devart.Data.Oracle;provider connection string="User Id=theusername;Password=thepassword;Server=theTNSname"" providerName="System.Data.EntityClient" />
</connectionStrings>
这是异常信息:
AppName.Tests.AccountRepositoryTests.GetByContactId:
System.Data.EntityException : The underlying provider failed on Open.
----> System.InvalidOperationException : Can not obtain Oracle client information
from registry. Make sure that Oracle Client Software is installed, or use
Direct mode of connecting to server.
注意:Web 和单元测试程序集都设置为编译到任何 CPU
。我在 64 位 Windows 7 上运行 32 位 Oracle 10g 数据库。我发现一篇文章似乎表明它与需要为 x86 的平台相关,但我的 Web 项目设置为 Any CPU
并且工作正常。
最佳答案
我遇到了类似的问题:Win7 64位DevArt with 32位Oracle。
对于 Web 项目,可以与任何 CPU
配合使用,但对于控制台和单元测试项目则失败。我通过在调试
模式下为测试和控制台项目设置x86
来修复它(或解决它)。
关于entity-framework - Entity Framework 4.3 到 Oracle : Web project works, NUnit 没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10353231/