【发布时间】:2012-07-31 15:32:06
【问题描述】:
尝试使用实体框架打开连接时,我不断收到此错误。 我可以毫无问题地从数据库更新模型,但是当我在调试中运行代码时,它会出现此错误。 (在 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"}
[/Edit2]
[编辑 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 位??
[/Edit3]
【问题讨论】:
-
添加您的 .config 连接字符串(没有真实姓名/密码)。此错误听起来像是配置问题。
-
添加了 .config 连接字符串 - 我同意我认为这是一个配置问题,只是不知道是什么:(
-
您是否收到另一条“打开时失败”的消息,例如“管道上没有进程”或其他内容
-
呃——是的,既然你问了! (我之前没有注意到!)请查看上面的编辑 - 似乎正在尝试连接到 SQL Server。
-
请检查您的连接字符串在哪里有正确的数据源名称比较 TNSNames.Ora 或 Sql.Ora
标签: c# wcf entity-framework