I have a console application which is doing a standard:
new SqlConnection("<connection string>").Open()
but is timing out with the below exception (eventually):
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: TCP Provider, error: 0 - The wait operation timed out.) ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
while attempting to open a connection to an (Azure hosted) SQL Server 12 instance. I'm having trouble pinpointing what's cause the problem, as:
.NET 4.5.2, VS15.0.0, Win10
Any ideas appreciated, I'm at a loss what could be causing this.
Edit: Seems to have started working. I'm not exactly sure why, but possibly the upgrade to VS15.1 did the trick. Thanks all for suggestions.
Just a shot in the dark, but are you a consultant who works from home? I had the exact same thing start happening to me today, however, I have not even verified that it still works in VS2015 or Linqpad like you have. I first check to see if I am still connected to the VPN and that my connection has not dropped.
Even if you are connected, I had this situation happen to me only once since I started here but the VPN said I was connected and I could reach Avocado but not COSMOS or any file shares. It was like a half-connected state, which I had to disconnect and reconnect a few times to get rid of. I also cleared my saved credentials from the VPN connection.
Maybe try these and see if this helps? If not, please let me know once you figure it out. Thanks!
You are using Azure Host, try the following methods:
1) First check you are connected to database from within vs 2017
From within vs2017, display Server explorer (menu->view->server explorer)
You find a tree with azure node.
Configure the connection to azure (sql server) and connect to database.
if success connection, review the generated connection string (Is it different? use it in your application)
Success connection means : No blocking for firewall, it's independent of debug/release mode or type of application: console/web/.... and the connection string is valid
2) Generate two executable program one in debug mode , and the second in release mode.
Use the connection string directly (without reading it from the configuration file(to isolate the root of the problem).
Run the two console application in your development environment (that run vs 2017) and other machine (don't have vs 2017 installed).
Record your finding.
Be sure, you don't use compilation flag in debug mode in source code that may affect connection.
3) review the following posts, it may help:
Azure SQL Database connection exception (System.Data.SqlClient.SqlException is thrown )
Azure Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'null'
Let me know the results of 1 and 2
3)The last step (using Data Tracing in ADO.NET)
If something strange during applying method 1 or 2, we may have to use data tracing in ado.net to discover the magic :) as described in: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/data-tracing
Could you try or check any of these:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With