"The underlying provider failed on Open"

c# entity-framework wcf

Question

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]

1
3
8/1/2012 11:22:25 AM

Accepted Answer

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
9/14/2012 3:37:19 PM

Popular Answer

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**"


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow