Error: "Specified Cast Not Valid"
Hello...
I have an error "Specified cast not valid" when I try updating a database using SQL line.
the SQL line is:
"UPDATE tblTableName SET fldFieldName='" & String & "' WHERE fldID=" & Integer
it looks like something is killing the connection because with error traping once the error occurs, it never works since.
please help me find the source for the problem.
Problems not in semafore !!
Hey.
The problems I have are not in the semafore....
the reason why I have several connections and sevral threads at the same time is because I have a exe file that scans the Internet and look for some things, because an avarage speed of this exe using the internet is 10 k/s, I execute about 10 at the same time and the speed is always at my maximum connection speed at the office (750 kb/s - 96 k/s).
using object oriented programming, I have an object that update the database before, during and after the exe is running.
if 2 or more exe ended at the same time, the connections will collapse. that's why I am using semafore.
the problem is not with the semafore, the problem is with the connection...
I am updating 50000 lines in the DB and suddenly it stops working with the error (exception) "Specified cast not valid".
even if I put it outside the semafore - the same...
using an other connection - the same...
deleting the problematic lines - the same (will get stuck on the next access to the DB)..
it looks like some action I made have caused an error in the DB and this error locks the DB for other connections.
here is some code...
mDB is an object for connecting the DB.
the While is for Retries defined by the Setup Object (SetupO)
Private Sub TaskEnded(ByVal CrwID As Integer, ByRef HandledTask As Task)
Dim Itm As ListViewItem
Dim Rty As Integer = 0
Dim DtSet As DataSet
Dim DtRow As DataRow
Dim SqlStr As String
Dim ScanTimeStr As String
SyncLock Me
ScanTimeStr = Now.Date & " " & Now.TimeOfDay.ToString
Rty = 0
While Rty <= SetupO.DBRetries
Try
SqlStr = "UPDATE tblURLs SET fldLastScaned='" & ScanTimeStr & "' WHERE fldTaskID=" & HandledTask.TaskID
mDB.Execute(SqlStr)
Rty = 0
Exit While
Catch Ex As Exception
Thread.Sleep(100 * (CrwID Mod 10))
Rty += 1
LogObj.WriteLine("Retry " & Rty & " for finishing task " & HandledTask.TaskID)
If Rty = SetupO.DBRetries Then
ErrObj.HandleError(Ex)
Exit While
End If
End Try
End While
While Rty <= SetupO.DBRetries
Try
mDB.Execute("UPDATE tblTasks SET fldStatus=" & Task.TaskStatus.Completed & " WHERE fldID=" & HandledTask.TaskID)
Exit While
Catch Ex As Exception
Thread.Sleep(100 * (CrwID Mod 10))
Rty += 1
LogObj.WriteLine("Retry " & Rty & " for finishing task " & HandledTask.TaskID)
If Rty = SetupO.DBRetries Then
ErrObj.HandleError(Ex)
Exit While
End If
End Try
End While
Try
For Each Itm In dlTasks.Items
If Itm.Text = HandledTask.TaskID Then
Itm.SubItems(3).Text = "Compelted"
Exit For
End If
Next
Catch Ex As Exception
ErrObj.HandleError(ex)
End Try
End SyncLock
End Sub