locked
Pre-login handshake SSL error but only when running standalone RRS feed

  • Question

  • My application is unable to connect to a local instance of SQL Server Express 2008 when it's running independently (i.e. when I launch it from the command line) but it works fine when I'm using the VS 2010 designers, and when I'm running it as part of NUnit. I originally thought this was an Entity Framework problem, so I posted this thread about it, but further investigation has shown that I get the same error with a plain SqlConnection, so it's not a problem specific to the EF.

    When I execute the following code at application startup:

     

    using(var conn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=Accounts;User ID=test;Password=test;MultipleActiveResultSets=True"))
    {
     conn.Open();
    
     var cmd = new SqlCommand("select count(*) from Actors") {Connection = conn};
     cmd.ExecuteScalar();
    
     conn.Close();
    }
    
    

     

    I get this exception:

     

    System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The specified data could not be decrypted.)
     at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
     at System.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(Boolean encrypt, Boolean trustServerCert, Boolean& marsCapable)
     at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity)
     at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
     at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
     at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
     at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
     at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
     at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
     at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
     at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
     at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
     at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
     at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
     at System.Data.SqlClient.SqlConnection.Open()
     at GDNet.Accounts.AccountsService.OnStart(String[] args) in C:\Users\Richard\
    Documents\Visual Studio 2008\Projects\V5-trunk\Services\AccountsBLL\AccountsService.cs:line 42

     

    The same connection setup works flawlessly when I use SSMS or when I use VS 2010's database connections stuff. (VS2010 is what built the connection string for me).

    I'm unclear as to why the SSL provider's even being invoked - I don't want a secure connection and haven't configured one. "Force Encryption" is not turned on for the server.


    Richard Fine
    • Edited by Richard Fine Tuesday, May 18, 2010 11:51 AM fixed thread link
    Tuesday, May 18, 2010 11:50 AM

Answers

  • Fixed it. It appears that the problem was caused by Visual Studio not correctly upgrading the BCrypt.NET project from .NET 2.0 to .NET 4.0.


    Richard Fine
    • Marked as answer by Richard Fine Tuesday, May 25, 2010 10:28 AM
    Tuesday, May 25, 2010 10:27 AM

All replies

  • I'm using the BCrypt.NET library in my project, and it looks like if I remove the reference to it (and corresponding code) then everything starts working. Going to investigate further, but it's very strange that simply referencing another assembly can break things in this way...
    Richard Fine
    Tuesday, May 18, 2010 10:57 PM
  • Hi Richard,

     

    Glad to hear that you have found the potential issue, which may be caused by BCrypt.NET.   If we only refer to the assembly of BCrypt.NET and not using it, how is the normal SqlConnection working?  

     

    BTW, if you can sure that the problem is caused by BCrypt.NET, I would recommend to consult the writer of the assembly to further investigate this issue.  

     

    Have a nice day!

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, May 19, 2010 1:27 AM
  • Hi Richard,

     

    How is the problem now?  

     

    Have a nice day!

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, May 24, 2010 1:26 AM
  • Fixed it. It appears that the problem was caused by Visual Studio not correctly upgrading the BCrypt.NET project from .NET 2.0 to .NET 4.0.


    Richard Fine
    • Marked as answer by Richard Fine Tuesday, May 25, 2010 10:28 AM
    Tuesday, May 25, 2010 10:27 AM