After installing VS11 Beta SqlException occurs when connecting to remote databases

Answered After installing VS11 Beta SqlException occurs when connecting to remote databases

  • 2012年3月12日 16:19
     
      コードあり

    Just recently, I started having problems connecting to remote databases from .NET.  The only thing I can think of that I installed recently that might have caused this is Visual Studio 11 Pro Beta.  I have sent sample code to coworkers that can still connect just fine, so it is definitely a client issue. I can still connect to a local database on my machine without any problems. I have since uninstalled VS11 Beta in hopes that it would fix this issue, but it still persists.  I am not having any issues connecting to these same servers via SSMS, only in code.

    This is also happening when trying to connect to remote databases from Server Explorer in VS2010.

    Here is the code I'm using:

    using(IDbCommand command  = new SqlCommand())
    {
          command.CommandText = "sp_databases";
          command.CommandType = CommandType.StoredProcedure;
          command.Connection  = new SqlConnection(@"Data Source=remoteservername;User ID=username;Password=password;Database=master;Encrypt=False");
          
          IDbDataAdapter adapter = new SqlDataAdapter();
          adapter.SelectCommand = command;
          
          DataSet set = new DataSet();
          
          adapter.Fill(set);
          
          command.Connection.Close();
    }

    The SqlException I'm getting has the following message and stack trace:

    "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.)"

       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
       at System.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean& marsCapable)
       at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover)
       at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject, Boolean withFailover)
       at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
       at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, SqlConnection owningObject, Boolean redirectedUserInstance)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
       at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey)
       at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
       at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.Open()
       at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)


すべての返信

  • 2012年3月12日 18:57
     
     
    I didn't realize that when uninstalling VS 11, the .NET Framework 4.5 beta was still installed.  After uninstalling the .NET Framework 4.5 Beta, (and reinstalling .NET Framework 4), everything is working again.
    • 回答としてマーク David Snedecor 2012年3月12日 18:57
    • 回答としてマークされていない David Snedecor 2012年7月6日 13:39
    •  
  • 2012年3月12日 21:26
    モデレータ
     
     

    Hello,

    Thanks to have found and provided the explanation of your problem.

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

  • 2012年3月23日 12:25
     
     
    what is the namespace to work with sql in visual studio 11..?

    A

  • 2012年3月23日 15:31
    モデレータ
     
     

    Hello,

    It depends of the .Net Framework you have installed :

    .Net Framework 4.5 ( be careful : that's a Beta one )

    the main one is http://msdn.microsoft.com/en-us/library/system.data.sqlclient(v=vs.110).aspx

    and more generally :

    http://msdn.microsoft.com/en-us/library/gg145028(v=vs.110).aspx 

    for .Net Framework 4.0 :

    http://msdn.microsoft.com/en-us/library/gg145028(v=vs.100).aspx 

    and mainly http://msdn.microsoft.com/en-us/library/system.data.sqlclient.aspx

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

  • 2012年3月23日 15:47
     
     

    Hello

    Thanks ,but while typing i am not getting "system.data".should i have to add some references.?

    I am using beta version of visual studio 11


    A


  • 2012年3月23日 15:50
     
     
    This is not really related to the original post. Maybe you should create a new topic.
  • 2012年3月23日 15:54
     
     
    I know sorry for that.I had posted earlier but coudn't get reply...so i posted beneath this post.!

    A

  • 2012年7月6日 13:39
     
     回答済み

    I have an update on this issue.  It turns out this is being caused by a code change in the .NET framework 4.5 that is interfering with 3rd party software that intercepts Winsock calls. (This kind of software is called a Base Service Provider, or Layered Service Provider).  In short, the 3rd party is going to have to update their software to support .NET 4.5.

    Here is the relevant Connect article:

    http://connect.microsoft.com/VisualStudio/feedback/details/745004/net-4-5-sql-connection-pre-login-handshake-error