SQL Azure: SSL Provider, error: 0 - The wait operation timed out
Asked Answered
A

1

2

I have a .NET web app that connects to SQL Azure with no problem from my local machine. Then, on the same machine, I've created another command-line .NET app in the same solution, copied the connection string from web.config to app.config, referenced the same assemblies with the web server (my connection/Entity Framework/model layer is on an assembly of its own) and tried to access my database. I'm getting the following error:

Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll

Additional information: A connection was successfully established with the server, 
but then an error occurred during the pre-login handshake. (provider: SSL Provider,
error: 0 - The wait operation timed out.)

Now, before you point out to many other questions out there, let me tell you in advance:

  • A .NET app with the same .NET version, on the same computer/solution is able to access the same database using the very same connection string and using the same assemblies/package versions etc. with no issue.
  • I've cleaned/rebuilt my solution, restarted Visual Studio and restarted my PC multiple times.
  • I've executed netsh Winsock reset successfully, and restarted my PC afterwards.
  • There are no antivirus/antimalware or firewall on my PC. There has never been anything in that sense other than the Windows Firewall and built in Windows 10 components. (yep, sure, no Panda Antivirus in particular. nope, no bloatware too, it's a original Windows 10 installation, not an OEM one)
  • I've tried with Windows Firewall both on and off, doesn't seem to affect.
  • The machine is running as a virtual machine on Parallels, if it makes any sense. There are no multiple network adapters available to Windows, so both my web app and console app are using the same "Internet connection" in that sense.
  • The connection timeout is 30 seconds, though I get the error immediately, not after 30 seconds. (it says that it has connected successfully anyways)
  • Both projects run on the same Windows 10 machine, debugged through Visual Studio 2015 Update 3, are built against .NET Framework 4.6.
  • I haven't even touched the problematic project in the last few weeks and it used to work perfectly a few weeks ago.
  • As anything that might be suspicious: I've got Fiddler installed, but I've always had it installed at the times it used to work too. In the few weeks, AFAIR, I've just installed Steam and Visual Studio 2017 RC but they aren't open.
  • I'm not getting any suspicious errors etc. at Azure side.
  • I can access the server with the same credentials using SQL Server Management Studio, and query the database with no issues. (I'm having the same problem both with SSMS open, closed, and/or after restarting with/without opening it).
  • I've seen countless number of questions regarding the same problem, however they almost all point to antivirus/firewall and resettting winsock and I've already done it.

Here is my connection string exactly from the config file (sensitive info replaced with XXXX):

<connectionStrings>
    <add name="Data" connectionString="Server=tcp:XXXX.database.windows.net,1433;Database=XXXX;User [email protected];Password=XXXX;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>

Remember, the very same connection string is also used in the other project and it works with no issues.

I'm out of ideas. What might be wrong?

Atman answered 6/12, 2016 at 16:16 Comment(1)
As this is encrypted connection, there can be issues with SSL from .Net side. You can try looking for ServicePointManager in your 'working' app - maybe there are some hacks re certifcate / tls version etcEliseelisee
R
1

Server=tcp:XXXX.database.windows.net,1433;Database=XXXX;User [email protected];Password=XXXX;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True;App=EntityFramework"

The connection string seems ok. And according to your description, the console application and web application are in same solution and run on same local environment, if firewall rules prevent apps from connecting to Azure SQL database, both applications should not work. It is difficult to reproduce the issue, I create a console application to create table and add records to Azure SQL database via Entity Framework Code First approach, the application works fine on my side.

Dbcontext

class BloggingContext: DbContext
{
    public BloggingContext()
        : base("name=Data")
    {
    }

    public virtual DbSet<Blog> Blogs { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
    }

}

Model class

class Blog
{
    public Blog(){}

    public int BlogId { get; set; }

    [StringLength(200)]
    public string Name { get; set; }

    [StringLength(200)]
    public string Url { get; set; }
}

Main method

class Program
{
    static void Main(string[] args)
    {

        using (var db = new BloggingContext())
        {
            Console.Write("Enter a name for a new Blog: ");
            var name = Console.ReadLine();

            var blog = new Blog { Name = name };
            db.Blogs.Add(blog);
            db.SaveChanges();

            var query = from b in db.Blogs
                        orderby b.Name
                        select b;

            Console.WriteLine("All blogs in the database:");
            foreach (var item in query)
            {
                Console.WriteLine(item.Name);
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }

    }
}

You could create a new console application with my sample code to test whether it works. Or you could run your application on another computer to make sure whether same issue will appear.

Besides, please make sure whether you could open a database connection using the following code in your console application.

static void Main(string[] args)
{
    using (var connection = new SqlConnection(
        "Server=tcp: XXXX.database.windows.net,1433;Database= XXXX;User ID= XXXX;Password= XXXX;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True;App=EntityFramework"
        ))
    {
        connection.Open();
        Console.WriteLine("Connected successfully.");

        Console.WriteLine("Press any key to finish...");
        Console.ReadKey(true);
    }
}
Rateable answered 7/12, 2016 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.