我试图运行此方法,但有时会出错,有时运行平稳。我不知道出了什么问题。有任何想法吗?
public bool NewArchive(string appId, string fileUrl, long length, string thumbUrl)
{
ConnectIfClosed();
string query = "INSERT INTO archive (appid, file_url, thumb_url, length) " +
"VALUES ('" + appId + "', '" + fileUrl + "', '" + thumbUrl + "', '" + length + "');";
bool result;
using (MySqlCommand cmd = new MySqlCommand(query, sqlConnector))
{
try
{
cmd.ExecuteNonQuery();
result = true;
}
catch (Exception ex)
{
mysqlerror = ex.ToString();
result = false;
}
}
return result;
}
这是我有时会遇到的例外情况。首先,我认为这与不cmd
正确处理有关..但我不确定。
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.EndOfStreamException: Attempted to read past the end of the stream.
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, Int32& insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& 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.ExecuteReader()
at ScrSnap.Sql.GetRowValueFromArchive(String row, String where, String wherematch) in C:\Users\Ben\Documents\Visual Studio 2010\Projects\Image software\ScrSnap 4\ScrSnap 4\Sql.cs:line 156