Skip to content

SQLDependency Warning: Fatal error 682 occurred at {Date}. Note the error and time, and contact your system administrator.

January 24, 2012

I kept getting this error and I could find nothing on it except “recreate your table”. Recreating my table did not fix it.

I ended up fixing it by changing this:

Using cmd As New SqlCommand("SELECT Field1, Field2 FROM dbo.tbl_CG_SystemStatus WHERE Field3= @Field3", sqlConn) With {.Notification = Nothing}
    cmd.Parameters.AddWithValue("@Field3", Field3)

    Dim dep As New SqlDependency(cmd)
    AddHandler dep.OnChange, AddressOf dep_OnChange
End Using
    

to this:

Using cmd As New SqlCommand(String.Format("SELECT Field1, Field2 FROM dbo.tbl_CG_SystemStatus WHERE Field3= '{0}'", Field3), sqlConn) With {.Notification = Nothing}
    Dim dep As New SqlDependency(cmd)
    AddHandler dep.OnChange, AddressOf dep_OnChange
End Using
    
Advertisements

From → .Net, SQL

2 Comments
  1. You actually should use a stored procedure instead of passing sql text to the command. Your SQL server will have to recompile this call every time it is called. We found that our sql calls were about 100 times faster when converted to a stored procedure.

    • Thanks for the tip. I always use stored procedures for updates/inserts/deletes and most of the time when I am querying. Occasionally on simple queries I take the path of least resistance. If I did use a stored procedure how would I pass the parameter given the current problem?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: