2012-06-21 5 views
0

Я делаю обычная таблица обновление отсканироватьфатальная ошибка во время чтения данных

Using connect1 As New MySqlConnection(ConnectLocalhost.serverString) 
    connect1.Open() 
    Dim cmd = New MySqlCommand("set net_write_timeout=99999; set net_read_timeout=99999", connect1) ' // Setting tiimeout on mysqlServer 
    cmd.ExecuteNonQuery() 

    Dim BusinessReader = selectSomeQuery("Select * from tablebusiness limit 800,10000000", connect1) 

    Do While BusinessReader.Read 'random exception here 

Иногда я получил эту ошибку

MySql.Data.MySqlClient.MySqlException was unhandled 
    ErrorCode=-2147467259 
    Message=Fatal error encountered during data read. 
    Number=0 
    Source=MySql.Data 
    StackTrace: 
     at MySql.Data.MySqlClient.MySqlDataReader.Read() 
     at dreamhost.Business.InsertLocalhost() in \\work\c\business\fromwork\currentprojects\program\library\vb.net\badger.vb:line 1849 
     at dreamhost.Business.surFoursquare() in \\work\c\business\fromwork\currentprojects\program\library\vb.net\badger.vb:line 1939 
     at dreamhost.traverseweb._Lambda$__92() in \\work\c\business\fromwork\currentprojects\program\library\vb.net\traverseweb.vb:line 77 
     at dreamhost.buttonClicking.startAndStopClickingButton(Object sender, Action SomeSub) in \\work\c\business\fromwork\currentprojects\program\library\vb.net\buttonclicking.vb:line 45 
     at dreamhost.traverseweb.foursquare_Click(Object sender, EventArgs e) in \\work\c\business\fromwork\currentprojects\program\library\vb.net\traverseweb.vb:line 77 
     at System.Windows.Forms.Control.OnClick(EventArgs e) 
     at System.Windows.Forms.Button.OnClick(EventArgs e) 
     at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 
     at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
     at System.Windows.Forms.Control.WndProc(Message& m) 
     at System.Windows.Forms.ButtonBase.WndProc(Message& m) 
     at System.Windows.Forms.Button.WndProc(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
     at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
     at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 
     at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 
     at System.Windows.Forms.Application.Run(ApplicationContext context) 
     at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() 
     at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() 
     at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) 
     at dreamhost.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: MySql.Data.MySqlClient.MySqlException 
     ErrorCode=-2147467259 
     Message=Reading from the stream has failed. 
     Number=0 
     Source=MySql.Data 
     StackTrace: 
      at MySql.Data.MySqlClient.MySqlStream.LoadPacket() 
      at MySql.Data.MySqlClient.MySqlStream.ReadPacket() 
      at MySql.Data.MySqlClient.NativeDriver.FetchDataRow(Int32 statementId, Int32 columns) 
      at MySql.Data.MySqlClient.Driver.FetchDataRow(Int32 statementId, Int32 columns) 
      at MySql.Data.MySqlClient.ResultSet.GetNextRow() 
      at MySql.Data.MySqlClient.ResultSet.NextRow(CommandBehavior behavior) 
      at MySql.Data.MySqlClient.MySqlDataReader.Read() 
     InnerException: System.IO.IOException 
      Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. 
      Source=MySql.Data 
      StackTrace: 
       at MyNetworkStream.HandleOrRethrowException(Exception e) 
       at MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
       at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
       at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count) 
       at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count) 
       at MySql.Data.MySqlClient.MySqlStream.LoadPacket() 
      InnerException: System.Net.Sockets.SocketException 
       ErrorCode=10054 
       Message=An existing connection was forcibly closed by the remote host 
       NativeErrorCode=10054 
       Source=System 
       StackTrace: 
         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) 
       InnerException: 

Все, что я хочу, чтобы программа просто «продолжить», когда это вещь случается. Но это кажется невозможным. Поэтому, я думаю, мне нужен способ убедиться, что эта ошибка не происходит. Это случается случайным образом 800 записей или около того.

Похоже, что соединение принудительно закрыто удаленным хостом. В этом случае я просто хочу пойти туда, где все осталось и перезапустить снова.

+0

возможно дубликат [MySQL Exception - фатальная ошибка при чтении данных] (http://stackoverflow.com/questions/2546115/mysql-exception-fatal-error-encountered-during- данные чтения) – nawfal

ответ

1

Может быть много причин, по которым соединение падает (загрузка сервера, сетевая проблема и т. Д.). То, что ваша программа сбой, говорит о том, что ваш код базы данных не защищен оператором try. Если вы делаете что-то вроде этого:

try 
    Using connect1 As New MySqlConnection(ConnectLocalhost.serverString) 
     connect1.Open() 
     Dim cmd = New MySqlCommand("set net_write_timeout=99999; _ 
      set net_read_timeout=99999", connect1) 
     cmd.ExecuteNonQuery() 

     Dim BusinessReader = selectSomeQuery("Select *...", connect1) 

     Do While BusinessReader.Read 
      'random exception here' 
      '...more code' 
     Loop 
    End Using 
Catch ex As Exception 
    ' code breaks here on exception - recover from this point ' 
End Try 

Я не буду вдаваться в затяжных диссертации на обработке исключений, но есть много ресурсов там, если у вас есть внешний вид. Как вы с этим справитесь, это зависит от конкретной ситуации: нужно ли регистрировать исключение, записывать, какая была последняя успешная операция, пытаться ли возобновить работу с того места, где вы были, или попытаться ли все это сделать снова, уведомить пользователя и т.д.

MSDN - Try/Catch/Finally

Смежные вопросы