Search code examples
entity-frameworkiisentity-framework-4cassini

Entity Framework "The underlying provider failed on Open" - Cassini vs IIS


I have a service that uses EF to retrieve data from a SQL database.

The EF model is in a class library. In the class library the connection is configured as:

      <add name="APIC2CEntities"
     connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MYSERVER;initial catalog=MYDB;user id=MYUSER;password=THEPASSWORD;multipleactiveresultsets=True;App=EntityFramework&quot;"
     providerName="System.Data.EntityClient" />

This class library is referenced by a WCF service project. In webconfig I control the EF connection with:

      <add name="APIC2CEntities"
     connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MYSERVER;initial catalog=MYDB;user id=MYUSER;password=THEPASSWORD;multipleactiveresultsets=True;App=EntityFramework&quot;"
     providerName="System.Data.EntityClient" />

When my service is running in Cassini the data is retrieved correctly. When the service is running under IIS (Windows XP) the connection fails with the following exception:

The underlying provider failed on Open

with an inner exception telling me:

{"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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}

I understand that Cassini is running under my logged in account, and that IIS is running under the IUSR_MYMACHINE account, but my connection is not trusted, so this shouldn't matter...

How else might an EF connection be manipulated or controlled differently between IIS and Cassini?

Thanks,
Mark


Solution

  • Our resolution on this occasion was to force the connection to use tcp (using data source=tcp:MyServer in the connection string) and enabling TCP on the SQL box (oops!)..

    I still have no idea how the Cassini session was able to establish connection where the IIS session was not :-S

    Mark