当我尝试使用实体框架打开连接时,我一直收到这个错误。我可以轻松地从数据库更新模型,但是在调试代码时会出现此错误。(在Windows 2008虚拟机上运行)
错误出现的代码片段如下:
public partial class SpatialDatabase : global::System.Data.Objects.ObjectContext
{
try
{
using (EntityConnection conn = new EntityConnection(this.Connection.ConnectionString))
{
conn.Open(); // <== fails here
EntityCommand cmd = conn.CreateCommand();
...
这是连接到Oracle数据库的代码。
这段代码在其他地方似乎正常运行,所以我感觉问题出在连接上。 我们正在使用Oracle for .NET(ODAC)驱动程序。我不知道它是64位还是32位,但当更新模型时它可以工作,但在调试时不能。
(如果我知道要展示什么代码,我会展示更多的代码!)
来自app.config的连接字符串:
<connectionStrings>
<add name="SpatialDatabaseContext" connectionString="metadata=res://*/SpatialDatabase.csdl|res://*/SpatialDatabase.ssdl|res://*/SpatialDatabase.msl;provider=Oracle.DataAccess.Client;provider connection string="DATA SOURCE=ds_name_here;PASSWORD=password_here;PERSIST SECURITY INFO=True;USER ID=user_id_here"" providerName="System.Data.EntityClient" />
</connectionStrings>
[编辑]
System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
[Edit]
[编辑2]
上述可能是一个误导。我再次运行它,没有看到那个错误,但我看到了这个InnerException:
[Oracle.DataAccess.Client.OracleException] = {"ORA-12154: TNS:could not resolve the connect identifier specified"}
[编辑2]
[编辑3]
我尝试使用EFOracleProvider。它可以成功构建,但是当我尝试生成实体模型时出现以下问题:
Microsoft (R) EdmGen version 3.5.0.0
Copyright (C) 2008 Microsoft Corporation. All rights reserved.
error 7001: The provider did not return a ProviderManifestToken string.
Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Generation Complete -- 1 errors, 0 warnings
我安装了Oracle客户端组件的32位和64位版本。我应该如何选择运行32位或64位版本?