dotnet / SqlClient

Microsoft.Data.SqlClient provides database connectivity to SQL Server for .NET applications.
MIT License
817 stars 272 forks source link

A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - Undefined error: 0) #2640

Open Oriu opened 5 days ago

Oriu commented 5 days ago

Using Microsoft.Data. SqlClient on MAC M1 MAX's rider connection to SqlServer query error,But it can be done on the window。

Code: string connectionString = "Persist Security Info=True;TrustServerCertificate=True;Data Source=myaddress;User ID=myuserid;Password=mypassword;DataBase=mydbname";
using (SqlConnection connection = new SqlConnection(connectionString))
{ connection.Open();
using (SqlCommand command = new SqlCommand("SELECT * FROM myTable", connection))
{
command.ExecuteReader();
}
connection.Close();
}

Error message: Microsoft.Data.SqlClient.SqlException (0x80131904): A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - Undefined error: 0) at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParserStateObject.ThrowExceptionAndWarning(Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error) at Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync() at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket() at Microsoft.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer() at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value) at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at Microsoft.Data.SqlClient.SqlDataReader.get_MetaData() at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method) at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at Microsoft.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) at Microsoft.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at SqlSugar.AdoProvider.GetDataReader(String sql, SugarParameter[] parameters) at SqlSugar.AdoProvider.SqlQuery[T,T2,T3,T4,T5,T6,T7](String sql, Object parameters) at SqlSugar.AdoProvider.SqlQuery[T](String sql, SugarParameter[] parameters) at SqlSugar.AdoProvider.SqlQuery[T](String sql, Object parameters) at TestWeb.Controllers.WeatherForecastAppService.PostProducts(TestPage testPage) in /Volumes/magic/MyWork/MyCode/xy.libcore/TestWeb/AppServices/WeatherForecastController.cs:line 333 ClientConnectionId:1366f45c-7f42-4d3a-bdec-98b0006a4e58

chenxiang0114 commented 5 days ago

My Microsoft.Data.SqlClient already update to the version 5.2.1. but sqlserver not work image

If I use 2.1.7, SQL Server can work completely normally, but upgrading to 5.2.0 5.2.1 will not work

.net8

arellegue commented 5 days ago

Thank you for reporting this issue. Could you provide an event trace log, please. You can find more information at: https://learn.microsoft.com/en-us/sql/connect/ado-net/enable-eventsource-tracing?view=sql-server-ver16

Please provide 2 event trace logs, one from 2.1.7 and one for 5.2.1 versions of the SqlClient driver.

Once, we receive the above information, we can begin our investigation.

chenxiang0114 commented 4 days ago

nettrace.zip my computer is MacOS, so I can only provide log files with the suffix. nettrace. Can you parse them? If it doesn't work, could you please inform me of other collection methods for Mac OS (the document you sent above seems to be from Windows)

arellegue commented 4 days ago

The EventSource trace will work in Mac OS as long as you have dotnet SDK and runtimes installed for Mac OS.

https://learn.microsoft.com/en-us/dotnet/core/install/macos