"The underlying provider failed on Open"

2

I keep getting this error when trying to open a connection using entity framework. I can update the model from the database with no problems at all, but when I run the code in debug it gives this error. (Running on a Windows 2008 VM)

The code fragment where the error appears looks like this:

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();
            ...

This is connection to an Oracle database.

This code is apparently running ok elsewhere so I have a feeling it is to do with the connection. We are using an Oracle for .NET (ODAC) driver. I have no idea whether it's 64 or 32 bit, but it works when updating the model but not when run in debug.

(I would show additional code if I knew what to show!)

Connection string from 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>

[Edit]

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]

[Edit2]

The above might be a red herring. I ran it again and didn;t see that error, but I did see this InnerException:

[Oracle.DataAccess.Client.OracleException] = {"ORA-12154: TNS:could not resolve the connect identifier specified"}

[/Edit2]

[Edit 3]

I tried to use the EFOracleProvider instead. It builds ok, but when I go to generate the entity model I get this:

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

I have both 32 bit and 64 bit versions of the Oracle client components installed. How do I choose whether to run 32 bit or 64 bit??

[/Edit3]

c#
wcf
entity-framework
asked on Stack Overflow Jul 31, 2012 by CompanyDroneFromSector7G • edited Aug 1, 2012 by CompanyDroneFromSector7G

5 Answers

0

I found a couple of links, thought they would be helpful to you! Hence sharing here.

On referring to this blog post, http://th2tran.blogspot.in/2009/06/underlying-provider-failed-on-open.html This section I thought of sharing with you from this blog article. "So IIS is trying to access the database under the credential 'NT AUTHORITY\NETWORK SERVICE' . I looked that the db settings via SQL Server Management Studio and, sure enough, that account is not listed as one of the users allowed to connect. So I added him. And the web app was able to connect successfully."

Try this out!

If you already have taken care of it, then please refer to the following link: MSSQL Error 'The underlying provider failed on Open'

Hope this helps!

answered on Stack Overflow Jul 31, 2012 by Varun Shringarpure • edited May 23, 2017 by Community
0

Sorry if any of the above were not helpful to you. I just added them because you added SQL Server related things in [Edit]

Anyways, please check the following in SQL Server : http://www.sswug.org/articlesection/default.aspx?TargetID=44331

And in case of Oracle, please refer to the following links if they help..

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

Regards,

Varun Shringarpure

answered on Stack Overflow Jul 31, 2012 by Varun Shringarpure
0

The server was not found or was not accessible.

Means that your connection string points to a server that cannot be found. Most commonly (at least for me) that is due to a wrong Sql Server name, in your case it is likely something similar. Check the

Data Source=(local) 

part of the connection string points to a connection you can access with another tool / app

(eg. the app.config of the .edmx file should point to the same place)

answered on Stack Overflow Aug 1, 2012 by Kaido • edited Jun 26, 2017 by Luiso
0

For info, there was no fix.

I ended up abandoning the VM I was having the problem on and building another (well someone else built it!)

The problem is now gone.

0

In the connection string, for the datasource, make sure to use the full descriptor rather than the entry from TNSNames.ora. For example,

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

instead of

"data source=**my_tns_ds**"
answered on Stack Overflow Jan 27, 2017 by kmxr • edited Jan 27, 2017 by user247702

User contributions licensed under CC BY-SA 3.0