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

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="data source=MYSERVER;initial catalog=MYDB;user id=MYUSER;password=THEPASSWORD;multipleactiveresultsets=True;App=EntityFramework""
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="data source=MYSERVER;initial catalog=MYDB;user id=MYUSER;password=THEPASSWORD;multipleactiveresultsets=True;App=EntityFramework""
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

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

I think the issue is still in connection string. If you are sure please do the following steps and test
Open blank notepad and save as connectionString.UDL
Open connectionString (just saved in step 1)
Under the connection tab: type server name (in my case: DESKTOP-IDSLV81) or IP as XXX.XXX.XXX.XXX,1433 where 1433 is default port the use respective username and password and the select Database(available DB is in Dropdown list)
Then press test connection if succeeded the press Ok button.
Open the connectionString.UDL file in notepad. The correct connection string is there and compare with your connection string in web.config

This solution is for someone facing this issue while deploying windows application,
I know this is late, but this maybe useful for someone in future, In my scenario, purely this is a connection string issue I developed a windows application using entity framework (DB First approach) and I published it, the code was worked fine on my machine, but it's not worked on the client machine
Reason for this issue:-
I updated the client machine connection string in App.config file, but this is wrong, if that is a windows application, then it will not read the connection string from App.config (For deployed machines), it will read from .exe.config file,
So after deployment, we need to change the connection string in "AppicationName".exe.config file

Related

referenced dll suddenly cannot find sql server

Its the strangest thing. I have a project that uses a library to call a web service. When the referenced dll is called it fails with :
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)
Inside the dll its getting the connection string via:
string strConnection = global::ThisTroublesomeLibrary.Properties.Settings.Default.prodConnectionString;
I have checked the connection string properties they are correct. Also all the other sites including the one calling this library has no problem finding sql server. I have checked the web service that the dll library calls & it seems to be working and returning correct data.
Here is my connection string format:
Data Source=mySQLSERVER;Initial Catalog=Thedatabaseimtryingtoreach;Integrated Security=False;Persist Security Info=True;User ID=drzounds;Password=itsasecret;
I just don't get it
firewall was blocking the sql connection

Creating Azure Hybrid Connection with Hybrid Connection Managaer

I have some REST APIs deployed to an app service an Azure.
I have added a hybrid connection to the app service, and deployed the hybrid connection manager to the relay server which I verified can connect to the DB. Both show as "connected".
I am having trouble configuring it, as it is my first attempt at this. I have 2 questions that if someone could I would be very grateful.
The Hybrid Connection Endpoint host. Is this the DB server name, or name and instance?
The DB I want to connect to is on Server\Instance, but it will not allow the "\" at all in the name. I've tried just server, just instance, and IP, they all still gave the error "The server was not found or was not accessible".
Is the problem with the REST services config? They are using the Entity Framework, and have the connection string:
add name="WEBEntities" connectionString="metadata=res:///Models.WEB.csdl|res:///Models.WEB.ssdl|res://*/Models.WEB.msl;provider=System.Data.SqlClient;provider connection string="data source=server\instance;initial catalog=WEB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"
Do I need to change this to point the Hybrid Connection instead? If so, how?
Thanks for any help, it's very appreciated.
The host should be the FQDN of the server - e.g. server1.xyz.com. You can use a named instance but you must use a static port. Please review: https://learn.microsoft.com/en-us/azure/biztalk-services/integration-hybrid-connection-overview . You won't need to change your EF connection string if the hybrid connection is configured correctly.

TFS Email Configuration

We have moved our TFS data tier server to another machine. Everything was reconfigured and is working EXCEPT email alerts. Test emails are sent just fine. However, alerts are not happening. When I checked the event viewer, I'm seeing the following error:
ds:OLDSERVERINSTANCE db:Tfs_Configuration errors:-1 exception:System.Data.SqlClient.SqlException (0x80131904): 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)
So, it appears that the email is still looking at the old database (which has been retired). Where/how can I change this?
In case anyone else runs into this scenario. The TFSJobAgent wasn't smart enough on reboot to recognize the data tier change. Doing the following worked:
1. Stop iis
2. Stop the TFSJobAgent
3. Start the TFSJobAgent
4. Start iis

Servlet JNDI connection timing out

Our Java Servlet was developed on Eclipse Helios for Windows and runs on Tomcat 7. Recently a SQL Server database that it connects to using JNDI was migrated to a new server. I checked I could set up the connection to the new SQL server database using Eclipse and this was successful. I also checked I could connect using the connection details using SQL Server Management Studio. However when I amend the JNDI connection using the new connection details and run the relevant web service request in SoapUI I am being returned the message;
java.net.SocketTimeoutException: Read timed out
I have also imported the new SSL certificates created on the new server but that did not resolve the problem. I have tried extending the timeout but I don't think that is working. What is causing this new connection to fail when the original worked fine?

SqlConnection error Named Pipes Provider

A little background:
I have a Windows .NET application that is in use by approximately 40 field employees across North America. This program allows the users to enter data while in the field (away form internet access) and then synchronizes to our Sql Server 2005 database at night. A couple days ago, two of my users reported getting the following error when they performed an action that would attempt to connect to our server database (which uses .NET's SqlConnection class).
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: Named Pipes
Provider, error: 40 - Could not open a
connection to SQL Server)
Our field employees are typically operating on a hotel Wi-Fi connection, and at first I thought that they both coincidentally got on an "uncooperative" network the same day. The following day, having moved to different hotels, the problem went away for one of these users, but continued for the other.
Besides providing the error message, the purpose of this background is to point out that
this is the first time this issue has occurred in over a year of using this software, and
the majority of our users aren't having any problem connecting to our server database with the same software.
This makes me hesitate to think that the issue is at the server (most forums and blogs I've read on this error provide steps to ensure the SQL Server is configured properly).
Noticing the Named Pipes Provider portion of the error message, I guessed that maybe this user's computer or network was causing it to attempt connection via pipes rather than TCP, so I did try configuring the server to allow BOTH TCP/IP and Named Pipes for remote connections, where it was previously set to TCP/IP only. The error continued for this one user after changing this setting.
So now I'm left to brainstorm about what could be special about this one user's computer / software / internet connection that would hinder it from being able to connect to our SQL Server.
Our connection string does use our server's URL (not IP address), and I wondered if his laptop was having problems finding it by that address. However, he was able to access a website hosted from the same URL, so I guess the problem is somewhere else.
Any ideas would be greatly appreciated. Thanks!
You've probably long since solved this problem by now or moved on, but for those having similar problems with the Error 40/named pipes issue when connecting to a SQL server instance, the following simple solution worked for us:
You can force your client program to use TCP (or named pipes, or other available methods) by adding a prefix in your connection string.
For the .NET SQLConnection example, specify in the SQLConnection's connection string like so:
Server=tcp:192.168.0.1;Integrated Security=SSPI; database=sampledb
See this blog entry for more info.
Is it possible that they are being blocked by the hotel's firewall, which may only allow traffic on certain ports?