连接数据库时出现
Connection Timeout Expired. The timeout period elapsed while
attempting to consume the pre-login handshake acknowledgement. This
could be because the pre-login handshake failed or the server was
unable to respond back in time. The duration spent while attempting to
connect to this server was - [Pre-Login] initialization=0;
handshake=14997;

提示

Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=0; handshake=14997;

提示
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=0; handshake=14997;

An unhandled exception occurred while processing the request.
SqlSugarException: English Message : Connection open error . Connection Timeout Expired. The timeout period elapsed during the post-login phase. The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=48; handshake=124; [Login] initialization=0; authentication=0; [Post-Login] complete=14000;

An unhandled exception occurred while processing the request.
SqlSugarException: English Message : Connection open error . A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 35 - An internal exception was caught)

原因:

.net core 的System.Data.SqlClient支持的最低SqlServer版本是2008 r2 SP3,小于这个版本的就会报这个错。

解决

方式1:.netcore 连接使用 sqlserver
.net core 的System.Data.SqlClient支持的最低SqlServer版本是2008 r2 SP3 请先检查数据库版本

方式2:通过sqlserver控制管理工具,重启sqlserver服务进程

其他信息

Microsoft SQL Server 2008 R2 (SP1)
10.50.2550.0 (X64) Jun 11 2012 16:41:53 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1)

Connection string:

Data Source=192.168.1.6;Initial Catalog=DBName;Persist Security Info=False;User ID=username;Password=pass

This issue may be related to #16528.

Unfortunately, we cannot upgrade our SQL server service pack. The same application works fine on Windows. This also impacts Entity Framework .

Code:

using (SqlConnection connection = new SqlConnection(connectionString))
{
    SqlCommand command = new SqlCommand(queryString, connection);
    connection.Open();
    SqlDataReader reader = command.ExecuteReader();
    try
    {
        while (reader.Read())
        {
            Console.WriteLine(String.Format("{0}, {1}",
            reader["Id"], reader["Email"]));
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }
}
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐