【问题标题】:"The underlying provider failed on Open" [closed]“基础提供商在打开时失败”[关闭]
【发布时间】: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=&quot;DATA SOURCE=ds_name_here;PASSWORD=password_here;PERSIST SECURITY INFO=True;USER ID=user_id_here&quot;" 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


【解决方案1】:

如果以上任何内容对您没有帮助,我们深表歉意。我刚刚添加它们是因为您在 [Edit] 中添加了与 SQL Server 相关的内容

无论如何,请在 SQL Server 中检查以下内容:http://www.sswug.org/articlesection/default.aspx?TargetID=44331

如果是 Oracle,如果有帮助,请参考以下链接。

http://ora-12154.ora-code.com/ http://blogs.msdn.com/b/dataaccesstechnologies/archive/2010/06/30/ora-12154-tns-could-not-resolve-the-connect-identifier-specified-error-while-creating-a-链接服务器到oracle.aspx

问候,

Varun Shringarpure

【讨论】:

  • 您的所有链接似乎都与 SQL 服务器相关。也许我不清楚,但我根本没有使用 SQL Server。不过感谢您的建议:)
【解决方案2】:

我找到了几个链接,认为它们会对您有所帮助!因此在这里分享。

在参考这篇博文时,http://th2tran.blogspot.in/2009/06/underlying-provider-failed-on-open.html 这部分我想从这篇博客文章中与您分享。 “所以 IIS 正试图访问凭据 'NT AUTHORITY\NETWORK SERVICE' 下的数据库。我通过 SQL Server Management Studio 查看了数据库设置,果然,该帐户未列为允许连接的用户之一。所以我加了他。网络应用能够成功连接。”

试试这个!

如果你已经处理好了,那么请参考以下链接:MSSQL Error 'The underlying provider failed on Open'

希望这会有所帮助!

【讨论】:

  • 感谢 Varun 的建议 - 只是检查一下:考虑到我在 Visual Studio 而不是 IIS 中调试,并且数据库是 Oracle 而不是 SQL Server,这些是否相关?
【解决方案3】:

在连接字符串中,对于数据源,确保使用完整的描述符而不是 TNSNames.ora 中的条目。例如,

`"data source=(DESCRIPTION= (ADDRESS= (PROTOCOL=TCP) (HOST=**host_name**) (PORT=**1521**)) (CONNECT_DATA= (SERVER=dedicated) (SID=**db_instance**)))"`

而不是

"data source=**my_tns_ds**"

【讨论】:

    【解决方案4】:

    服务器未找到或无法访问。

    表示您的连接字符串指向一个无法找到的服务器。最常见的(至少对我来说)是由于错误的 Sql Server 名称,在您的情况下,它可能是类似的。检查

    Data Source=(local) 
    

    连接字符串的一部分指向您可以使用其他工具/应用程序访问的连接

    (例如.edmx文件的app.config应该指向同一个地方)

    【讨论】:

    • 我正在尝试连接到 Oracle 服务器。该消息出现过一次,我认为这只是一个红鲱鱼。我能够使用相同的连接详细信息从数据库中重建实体模型,只是无法在运行时连接。
    • 为了绝对确定,我会从工作文件中复制粘贴配置,然后追踪该错误:ora-12154.ora-code.com
    【解决方案5】:

    关于信息,没有修复。

    我最终放弃了我遇到问题的虚拟机并构建了另一个(其他人构建了它!)

    问题已经解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多