In advantage, when I subscribe to an event (via sp_CreateEvent) at what level is that event created? Per connection? Per Client? Database wide?
The application is that I have a long running application where occasionally ads connections are reset due to errors. Do I need to recreate (sp_CreateEvent) in addition to resubscribe (sp_WaitForEvent) when creating new connections?
Also, is there a way to check if a certain event already exists for my given connection/application/whatever level events exist at?
Events are created on a per database level, however any connection that wishes to wait on an event must create the event using
sp_CreateEvent. Think of it more likesp_CreateEventregisters a connection for an event as opposed to creating it.All connections must create/register for the event if they wish to wait on it, so if a connection dies due to an error and is re-created it must again call
sp_CreateEventandsp_WaitForEvent.There is no way to simply check if an event exists. Probably the best way to check is to call
sp_WaitForEventand check for an error. Specify 0 for the timeout if you want it to return right away. You could also callsp_CreateEventorsp_DropEventand check for errors, but you might have unintended consequences if the event exists or not.Read more about events in our online documentation.