Debug shows Error, no errors thrown

I have a simple peice of code that queries a database and returns a count. Everything works fine, I get all of the results that I expect, and no error messages are displayed. But, when I'm testing I noticed that my debug window is full of this message: "A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll"

Any idea what this is and why it's happening? What am I doing wrong?

Dim connection As SqlClient.SqlConnection
Dim command As SqlClient.SqlCommand
Dim dataObject As Object

' connectionString is built here... code not important

Try
' Open the connection
connection = New SqlClient.SqlConnection(connectionString)
connection.Open()

' Initialize the datareader
command = New SqlClient.SqlCommand("SELECT COUNT(name) AS RecordCount FROM sysdatabases WHERE filename='" & filePath & "'", connection)
dataObject = command.ExecuteScalar
recordsReturned = dataObject

' Close the connection
dataObject = Nothing
command.Dispose()
connection.Close()
connection.Dispose()
Catch ex As Exception
DisplayErrorMessage(ex)
End Try

' recordsReturned is evaluated and value is returned here
' Once again, this code is removed because it's not important

Public Sub DisplayErrorMessage(ByVal ex As Exception)
' Display the error message
MsgBox(ex.Source & ": " & ex.Message, MsgBoxStyle.Critical, My.Application.Info.ProductName)
End Sub
[1668 byte] By [MeatLander] at [2007-11-20 10:55:02]
# 1 Re: Debug shows Error, no errors thrown
MeatLander,

Some code in System.Data is throwing and then handling an InvalidOperationException exception. This is usually nothing to worry about.

If you want the debugger to stop your app and show you the line in your code that is ultimately causing the exception you can choose Exceptions from the Debug menu (2005) and indicate that you want exceptions of type System.InvalidOperationException to be thrown even if they would normally be handled.

Kerry Moorman
kmoorman at 2007-11-10 3:08:22 >
# 2 Re: Debug shows Error, no errors thrown
If it's nothing to worry about, then I don't care and I'll just leave it.

I was just afraid that I was writing bad code...
MeatLander at 2007-11-10 3:09:33 >
# 3 Re: Debug shows Error, no errors thrown
No error is nothing to worry about, sorry, I disagree here ( but not fighting ) :D

Here is more information on the First chance Exception :
http://blogs.msdn.com/davidklinems/archive/2005/07/12/438061.aspx

Read through it, then make a decision, yes, granted, a first chance exception is not really an exception, but still...
HanneSThEGreaT at 2007-11-10 3:10:32 >