locked
SqlConnection now failing, exception when connecting to remote instance RRS feed

  • Question

  • Hi,

    This is a fairly new problem I've run into - in between the time when I know this was working fine for me and now, I did some software installs, but have made an effort to roll things back as best as I could.  Some of the items installed included VS 2013 (preview), Microsoft Message Analyzer, Microsoft Monitoring Agent (never fully installed).

    The code in question that fails now is a simple:

    using (var conn = new SqlConnection("<my connection string>"))

    {

        conn.Open();

    }

    The Open fails with the following exception (SqlException):

    A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The message received was unexpected or badly formatted.)

    If I let it continue, the client handled exception is:

    The connection was not closed. The connection's current state is connecting. (InvalidOperationException)

    Things to note:

    1. Only fails when talking to a remote SQL instance - local ones work fine I'm assuming on the basis that it's using Shared Memory - when I disable that and use TCP only, it starts failing similarly for local instances

    2. I can connect to the remote instance using OSQL - so I'm strongly suspecting drivers are involved at some level

    3. This is being done on my host OS - I can run a VM on the same machine and do the very same code above and it *works* - so I have to believe it's local software/config on the host, not hardware and not remote hardware or software.

    4. Other connectivity health seems fine - I'm composing this message on the failing host.

    Any ideas on where I could turn next?  I'm trying to avoid a complete reinstall of everything - would be a terrible time suck for no good reason! :(

    Thanks,

    - J

    Friday, October 25, 2013 2:16 PM

Answers

All replies

  • Additional follow-up...  changing the target .NET framework version to 3.5 in a test harness actually *works*, so I can safely say it's something specific to my installation of .NET 4.0/4.5...  Unfortunately a "repair" for that doesn't seem easy, if anyone can point out how to address *that*, would appreciate it, thanks.

    - Joel

    Friday, October 25, 2013 8:03 PM
  • OSQL.  What version of SQL Server are you connecting to?  And what's your connection string?

    Also check this:

    Ability to connect to a SQL Server database from managed code that runs under the .NET Framework 4.5.

    The existing synchronous API code path was modified to add asynchronous support.

    The presence of non-IFS Winsock Base Service Providers (BSPs) or Layered Service Providers (LSPs) may interfere with the ability to connect to SQL Server. For more information, see SetFileCompletionNotificationModes API causes an IO completion port not work correctly with a non-IFS LSP installed  on the Microsoft Support website.

    Application Compatibility in the .NET Framework 4.5

    David


    David http://blogs.msdn.com/b/dbrowne/

    Friday, October 25, 2013 9:25 PM
  • I am having the exact same issue.

    I install the RC version and had the problem.  I then uninstalled it and it was fixed.  

    I have a support ticket but have not found a solution.

    What we have found is the Framework version 4.5.1 is the root cause and has something to do with System.Data.  If you install Visual Studio 2013 RTM.  Followed by an uninstall of the .NET Framework 4.5.1 and then reinstall .NET Framework 4.5, connections will work.

    However you will not be able to compile.  You can use most of the other features.

    Saturday, November 2, 2013 12:54 AM
  • I am also having the same issue.

    SQL Server Management Studio 2012, Visual Studio 2013 itself and any c# application crushes when connecting to remote SQL Server 2012

    And I can't uninstall .NET 4.5.1, cleanup tool jsut does nothing it seems, .NET 4.5 doesn't want to install after cleanup

    wtf



    • Edited by Chao ren Tuesday, November 5, 2013 1:58 PM
    Tuesday, November 5, 2013 12:35 PM
  • OSQL.  What version of SQL Server are you connecting to?  And what's your connection string?

    Also check this:

    Ability to connect to a SQL Server database from managed code that runs under the .NET Framework 4.5.

    The existing synchronous API code path was modified to add asynchronous support.

    The presence of non-IFS Winsock Base Service Providers (BSPs) or Layered Service Providers (LSPs) may interfere with the ability to connect to SQL Server. For more information, see SetFileCompletionNotificationModes API causes an IO completion port not work correctly with a non-IFS LSP installed  on the Microsoft Support website.

    Application Compatibility in the .NET Framework 4.5

    David


    David http://blogs.msdn.com/b/dbrowne/

    Why this is marked as an answer?? This is completely irrelevant
    Tuesday, November 5, 2013 2:00 PM
  • OSQL.  What version of SQL Server are you connecting to?  And what's your connection string?

    Also check this:

    Ability to connect to a SQL Server database from managed code that runs under the .NET Framework 4.5.

    The existing synchronous API code path was modified to add asynchronous support.

    The presence of non-IFS Winsock Base Service Providers (BSPs) or Layered Service Providers (LSPs) may interfere with the ability to connect to SQL Server. For more information, see SetFileCompletionNotificationModes API causes an IO completion port not work correctly with a non-IFS LSP installed  on the Microsoft Support website.

    Application Compatibility in the .NET Framework 4.5

    David


    David http://blogs.msdn.com/b/dbrowne/

    I am in the same boat.  I followed the post and it provides not solution.
    • Proposed as answer by Coach David Tuesday, November 5, 2013 7:44 PM
    • Unproposed as answer by Coach David Tuesday, November 5, 2013 7:44 PM
    Tuesday, November 5, 2013 5:52 PM
  • I followed Chao ren bread crumbs and found an answer.

    run from a command line

    netsh winsock reset

    • Proposed as answer by Coach David Tuesday, November 5, 2013 7:47 PM
    Tuesday, November 5, 2013 7:47 PM
  • FWIW I did end up solving my problem a while back.  Further to the diagnosis was the fact that in my test harness app that was failing when I targeted .NET framework 4.5, if I changed the targeting to 3.5, everything *worked*.  So it was clearly a .NET framework issue that I managed to resolve by restoring System.Data.dll from a working location - may not be the safest approach, but after that, everything was back to working even under .NET 4.5.  I'm now using VS2013 without any further issues.
    Tuesday, December 3, 2013 11:17 PM