尝试使用实体框架打开连接时,我不断收到此错误。我可以毫无问题地从数据库更新模型,但是当我在调试中运行代码时,它会出现此错误。(在 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)
[/编辑]
[编辑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
我安装了 32 位和 64 位版本的 Oracle 客户端组件。如何选择运行 32 位还是 64 位?
[/编辑3]