I have a somewhat weird problem with a program i'am writing in VB2005. When I debug the program and start 1 backgroundworker (got 8 different backgroundworkers in the program) in VB2005 nothing goes wrong, but when i'm starting 2 or more backgroundworkers I get an NullReferenceException when trying to read from a MySQL database (withing a few minutes). This error isn't always in the same backgroundworker, but is always in the same block of code in a backgroundworker (1 of 8 ). I tried different approaches in getting the results I need, for example with read1.HasRows(), but this also didn't workt... the MySQL table doesn't also seem to be the problem.
All 8 backgroundworkers peform the same task (Webcrawling). Please help me! Thanks!
Line 9 is where I get the error... This is a snippet from backgroundworker1, but is also randomly happens in the other 8 backgroundworkers as well... When I'am trying to read te content of read1 is says "Nothing" when the error occures... Line 5 was a suggestion from an other programmer @ www.vbmysql.com...
1 Dim mysqlquery01 As String = "" 2 Dim URLExistInDatabase1 As Boolean = True 3 Dim URLID1 As Integer = 0 4 mysqlquery01 = "SELECT * FROM `" & txtDatabase.Text & "`.`" & txtOutputTable.Text & "` WHERE URL='" & URL1 & "'" 5 MySQLcommand1.CommandType = CommandType.Text 6 MySQLcommand1.CommandText = mysqlquery01 7 MySQLcommand1.Connection = MySQLconn1 8 read1 = MySQLcommand1.ExecuteReader() 9 While read1.Read() 10 URLID1 = read1.GetString("ID") 11 End While 12 If URLID1 > 0 Then 13 URLExistInDatabase1 = True 14 Else 15 URLExistInDatabase1 = False 16 End If 17 read1.Close()
The MySQL connection (not in a backgroundworker):
Public MySQLconn1 As New MySqlConnection() Public MySQLcommand1 As New MySqlCommand() Public read1 As MySqlDataReader MySQLconn1 = New MySqlConnection() MySQLconn1.ConnectionString = "server=" & txtHost.Text & "; user id=" & txtUsername.Text _ & "; password=" & txtPassword.Text & "; database=" & txtDatabase.Text MySQLconn1.Open()
Vb2005 Asks at the line "While read1.Read()", to use the "new" keyword to create an object instance. But it is not possible to create a "new mysqldatareader" without getting an error... But maybe I'am doing it the wrong way...) When I read the value for read1 it says "Nothing", which is strange, because MySQLcommand1.CommandText has a value...