簡體   English   中英

從 .net 獲取 MySql 數據時出錯; (命令執行過程中遇到致命錯誤)

[英]Getting error when fetching MySql data from .net ; ( Fatal error encountered during command execution)

我正在從.Net 應用程序的 MySQL 獲取數據。 它有時會拋出錯誤,如下所示

MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered during command execution.
---> MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered attempting to read the resultset.
---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed.
---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
    at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
    --- End of inner exception stack trace ---
    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
    at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
    at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
    at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
    at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
    at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
    at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
    at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
    at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
    at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
    at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
    at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
    at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
    at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
    at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
    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)

我的代碼如下

_mySqlConn = new MySqlConnection(ConfigurationManager.ConnectionStrings["BiometricConnectionPush"].ToString());
_mySqlConn.Open();
_strQry = "SELECT * FROM biologs WHERE id>" + LastPunchId + " ORDER BY id ASC LIMIT " + RowLimit.ToString();

MySqlCommand _sqlCmd = new MySqlCommand();
_sqlCmd.CommandText = _strQry;
_sqlCmd.CommandTimeout = 100000;
_sqlCmd.Connection = _mySqlConn;
_sqlCmd.CommandType = CommandType.Text;

Data = new DataSet();
_mySqlDa = new MySqlDataAdapter(_sqlCmd);
_mySqlDa.Fill(Data);

System.IO.IOException: Unable to read data from the transport connection: 連接嘗試失敗,因為連接方在一段時間后沒有正確響應,或者建立連接失敗,因為連接的主機沒有響應。

System.Net.Sockets.SocketException:連接嘗試失敗,因為連接方在一段時間后沒有正確響應,或者連接失敗,因為連接的主機沒有響應。

無法聯系您的 MySQL 服務器,或者事情超時。

請注意,您已將命令超時明確設置為 10 秒; 如果由於某種原因執行您的查詢需要更多的時間,您會得到該異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM