Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

[vb.net] programma loopt vast op mysql exception

Pagina: 1
Acties:

  • trekker22
  • Registratie: Maart 2003
  • Laatst online: 17:34
ik heb een mysql programma in vb.net dat altijd moet door draaien zonder dat user een of andere fout melding krijgt (bv als mysql server offline is of overloaded is met connecties)

dit is de vb.net code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
        Dim connectstring = "Database=" & database & ";Data Source=" & host & ";User Id=" & user & ";Password=" & pass
        Dim MysqlConn As New MySqlConnection(connectstring)

        Dim myInsertQuery As String
        myInsertQuery = "UPDATE account SET version_service = " + version.ToString + ", update_service = NOW()  WHERE number = '" + account_id + "'"

        Dim myCommand As New MySqlCommand(myInsertQuery)
        myCommand.Connection = MysqlConn
        Try
            MysqlConn.Open()
            myCommand.ExecuteNonQuery()

        Catch ex As MySqlException
            lstDebug.Items.Insert(0, "MYSQL ERROR: " & ex.Message.ToString)

        Finally
            myCommand.Connection.Close()
        End Try


zover ik weet moet dit programma altijd doordraaien en mocht er iets in de mysql fout gaan het programma doorloopt er er iets in de listbox komt te staan. Echter na een aantal dagen loopt het programma soms vast met deze melding:

Unhandled exception has occured in your application.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
************** Exception Text **************
System.TimeoutException: 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.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.Common.MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   --- End of inner exception stack trace ---
   at MySql.Data.Common.MyNetworkStream.HandleOrRethrowException(Exception e)
   at MySql.Data.Common.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()
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at ScheduleCheck.ScheduleCheck.UpdateClientVersionDB(String database, String host, String user, String pass, String account_id, String version)
   at ScheduleCheck.ScheduleCheck.ProcessTick()
   at ScheduleCheck.ScheduleCheck.myTimer_Tick(Object sender, EventArgs e)
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


lijkt wel of tijdens de My SQL update er iets misgaat, maar dan moet er toch geen exception popup komen?

Als ik de MySql server uitschakel dan komt er wel in de lstbox een error melding en applicatie loopt door zonder interactie met de gebruiker?

  • Daos
  • Registratie: Oktober 2004
  • Niet online
Je vangt alleen MySqlException. Kan je niet alle exceptions afvangen? bv zoiets
Visual Basic .NET:
13
Catch ex As Exception

  • Woy
  • Registratie: April 2000
  • Niet online

Woy

Moderator Devschuur®
Daos schreef op zondag 16 juni 2013 @ 22:23:
Je vangt alleen MySqlException. Kan je niet alle exceptions afvangen? bv zoiets
Visual Basic .NET:
13
Catch ex As Exception
Dat is bijna altijd af te raden, hooguit op het hoogste niveau voor logging. Maar je kunt beter gewoon expliciet de exceptions die je verwacht afvangen. In dit geval zul je dus moeten kijken welke exceptions MySqlConn.Open() en myCommand.ExecuteNonQuery() kunnen gooien, en die afvangen en afhandelen.

In dit geval zul je dus ten minste de MySqlException en de TimeoutException af moeten vangen en afhandelen.

[ Voor 9% gewijzigd door Woy op 17-06-2013 08:31 ]

“Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.”


  • trekker22
  • Registratie: Maart 2003
  • Laatst online: 17:34
ok helemaal duidelijk; neem aan dat de TimeOut Exception niks mee werd gedaan!

  • PdeBie
  • Registratie: Juni 2004
  • Laatst online: 16:21
Daos schreef op zondag 16 juni 2013 @ 22:23:
Je vangt alleen MySqlException. Kan je niet alle exceptions afvangen? bv zoiets
Visual Basic .NET:
13
Catch ex As Exception
Afbeeldingslocatie: http://cdn.memegenerator.net/instances/400x/35377963.jpg
trekker22 schreef op maandag 17 juni 2013 @ 11:23:
ok helemaal duidelijk; neem aan dat de TimeOut Exception niks mee werd gedaan!
De TimeOut Exception wordt in je huidige code nog niets mee gedaan inderdaad.

  • Daos
  • Registratie: Oktober 2004
  • Niet online
Woy schreef op maandag 17 juni 2013 @ 08:31:
[...]

Dat is bijna altijd af te raden, hooguit op het hoogste niveau voor logging.
Logging van alle exceptions is juist wat hij wil.

  • Woy
  • Registratie: April 2000
  • Niet online

Woy

Moderator Devschuur®
Daos schreef op maandag 17 juni 2013 @ 12:25:
[...]


Logging van alle exceptions is juist wat hij wil.
Ja want als daar een StackOverflowException komt is dat de meest logische plek om te loggen! :?

“Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.”

Pagina: 1