“基础提供商在Open上失败”

时间:2012-07-31 15:32:06

标签: c# wcf entity-framework

尝试使用实体框架打开连接时,我一直收到此错误。 我可以从数据库中更新模型而没有任何问题,但是当我在调试中运行代码时,它会出现此错误。 (在Windows 2008 VM上运行)

出现错误的代码片段如下所示:

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)

[/编辑]

[EDIT2]

以上可能是红鲱鱼。我再次运行它并没有看到错误,但我确实看到了这个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]

5 个答案:

答案 0 :(得分:0)

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

在参考此博文时,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'

希望这有帮助!

答案 1 :(得分:0)

很抱歉,如果上述任何一项对您没有帮助。我刚添加它们是因为您在[编辑]

中添加了与SQL Server相关的内容

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

如果是甲骨文,如果有帮助,请参考以下链接。

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

答案 2 :(得分:0)

  

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

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

Data Source=(local) 

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

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

答案 3 :(得分:0)

有关信息,没有修复。

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

问题现在已经消失。

答案 4 :(得分:0)

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