底层提供程序在打开时失败。

3

当我尝试使用实体框架打开连接时,我一直收到这个错误。我可以轻松地从数据库更新模型,但是在调试代码时会出现此错误。(在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)

[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位版本?

添加您的 .config 连接字符串(不包含真实名称/密码)。这个错误看起来像是一个配置问题。 - Kaido
添加了.config连接字符串 - 我同意这是一个配置问题,只是不知道是什么 :( - CompanyDroneFromSector7G
你有没有收到另一条带有“打开失败”的消息,比如“管道上没有进程”之类的? - Kaido
额,是的,现在你问我才注意到!请查看上面的编辑 - 似乎正在尝试连接到 SQL Server。 - CompanyDroneFromSector7G
Yup DSN在ConnectionString和TNSNANES.ORA文件中是相同的。 - CompanyDroneFromSector7G
显示剩余3条评论
5个回答

1
服务器未找到或无法访问。这意味着您的连接字符串指向无法找到的服务器。最常见的情况(至少对我来说)是由于错误的Sql Server名称,您的情况可能类似。请检查。
Data Source=(local) 

连接字符串的一部分指向另一个工具/应用程序可以访问的连接

(例如,.edmx文件的app.config应该指向同一个位置)


1
我正在尝试连接到一个Oracle服务器。那个提示只出现过一次,我觉得它只是一个误导信息。使用相同的连接详细信息,我能够从数据库重建实体模型,只是在运行时无法进行连接。 - CompanyDroneFromSector7G
我会将配置从已工作的文件复制粘贴以确保绝对正确,然后去排查这个错误:http://ora-12154.ora-code.com/ - Kaido

1

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

参考这篇博客文章,http://th2tran.blogspot.in/2009/06/underlying-provider-failed-on-open.html 我想从这篇博客文章中与你分享以下部分。 "因此,IIS 正试图使用凭据 'NT AUTHORITY\NETWORK SERVICE' 访问数据库。我通过 SQL Server Management Studio 查看了数据库设置,确实发现该帐户未列为允许连接的用户之一。所以我添加了他。然后 Web 应用程序能够成功连接。"

试试这个方法吧!

如果你已经解决了问题,请参考以下链接:MSSQL 错误 'The underlying provider failed on Open'

希望这可以帮到你!


谢谢你的建议,Varun - 只是想确认一下:考虑到我在 Visual Studio 中运行调试,而不是在 IIS 中运行,并且数据库是 Oracle 而不是 SQL Server,这些建议是否仍然适用? - CompanyDroneFromSector7G

1

如果以上任何内容对您没有帮助,我很抱歉。我只是添加了它们,因为您在[编辑]中添加了与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-linked-server-to-oracle.aspx

此致敬礼,

Varun Shringarpure


你所有的链接似乎都与SQL Server有关。也许我没有表达清楚,但我根本没有使用SQL Server。不过还是谢谢你的建议 :) - CompanyDroneFromSector7G

1
在连接字符串中,对于数据源,请确保使用完整的描述符,而不是从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**"

0

补充一下,没有修复方法。

最终我放弃了出问题的虚拟机,重新建了一台(其实是别人建的)。

问题现在解决了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接