I have a method that calls ExecuteScalar for a Count(*) sql statement. It works fine for several iterations then all of a sudden it goes off and never returns. When it hangs it takes over 100% of my CPU. I get no error messages back so I have no clue what I am doing wrong. I have isolated my method from the rest of the code and open up and close the database connection within the method. Following is my isolated code. The odd thing is that when we upgraded our environment from ESRI Arc 9.1 to 9.2, visual studio 2005 and .NET Framework 2.x this error showed up. Works perfectly in ESRI 9.1, VS 2003 and .NET Framework 1.x. Any suggestions would be greatly appreciated.
Friend Function testScaler() As Integer
Dim sqlStr As String = "SELECT COUNT(*) FROM maps " & _
"WHERE [proj_id] = ? " & _
"AND [data_name] = ?" ' $NON-NLS$
Dim connectionString As String = _
"Provider=" & PaExtension.paProject.dbProvider & ";" & _
"Data Source=" & PaExtension.paProject.dbDataSource & ";"
Dim con As OleDbConnection = New OleDbConnection
con.ConnectionString = connectionString
con.Open()
Dim cmd As OleDbCommand = New OleDbCommand
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = sqlStr
addParameter(cmd, "[proj_id]", Me.projId) ' $NON-NLS$
addParameter(cmd, "[data_name]", Me.dataName) ' $NON-NLS$
Dim count As Integer
Dim bob As Object = Nothing
bob = cmd.ExecuteScalar() 'This is where after 4-5 times working it finally
' runs away and never returns.
If IsNothing(bob) Then
count = 0
Else
count = CInt(bob)
End If
cmd.Dispose()
cmd = Nothing
con.Dispose()
con = Nothing
Return count
End Function
Friend Function testScaler() As Integer
Dim sqlStr As String = "SELECT COUNT(*) FROM maps " & _
"WHERE [proj_id] = ? " & _
"AND [data_name] = ?" ' $NON-NLS$
Dim connectionString As String = _
"Provider=" & PaExtension.paProject.dbProvider & ";" & _
"Data Source=" & PaExtension.paProject.dbDataSource & ";"
Dim con As OleDbConnection = New OleDbConnection
con.ConnectionString = connectionString
con.Open()
Dim cmd As OleDbCommand = New OleDbCommand
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = sqlStr
addParameter(cmd, "[proj_id]", Me.projId) ' $NON-NLS$
addParameter(cmd, "[data_name]", Me.dataName) ' $NON-NLS$
Dim count As Integer
Dim bob As Object = Nothing
bob = cmd.ExecuteScalar() 'This is where after 4-5 times working it finally
' runs away and never returns.
If IsNothing(bob) Then
count = 0
Else
count = CInt(bob)
End If
cmd.Dispose()
cmd = Nothing
con.Dispose()
con = Nothing
Return count
End Function