Click here to Skip to main content
Licence 
First Posted 5 Dec 2004
Views 48,639
Bookmarked 24 times

SQL Server extended stored procedure to send UDP messages

By | 25 Apr 2005 | Article
SQL Server extended stored procedure to send UDP messages.
 
Part of The SQL Zone sponsored by
See Also

Introduction

I wanted to be able to announce SQL Server table updates so I modified the Microsoft sample extended stored procedure xp_hello. The source for this article will produce a DLL that can be placed in the \Program Files\Microsoft SQL Server\MSSQL\Binn directory and called from a regular stored procedure to send a UDP message. I chose UDP so there would be minimal execution time added (no TCP connection issues).

Be aware that this extended stored procedure is executed in SQL Server’s space so any errors/exceptions could crash SQL Server. This happened to me during development when I mistakenly called WSACleanup after sending an announcement, causing SQL Server to lose its network connections. In short, be very careful what you do within the DLL as it can affect SQL Server.

A sample SQL Server stored procedure that calls SQLAnnounceProc is:

CREATE PROCEDURE getTestTable
AS
BEGIN SELECT * FROM TEST_TABLE
declare @status int
declare @ret varchar(513)
declare @temp as varchar(128)
SET @temp = 'got ' + CAST( @@ROWCOUNT as varchar(16) ) + ' rows'
declare @ip varchar(32)
SET @ip = '127.0.0.1'
declare @port varchar(16)
SET @port = '15555'
exec @status = master.dbo.SQLAnnounceProc @ret OUTPUT, @ip, @port, @temp
END
GO

Of course, you will need to create a table named TEST_TABLE for testing purposes and call it from the Query Analyser using:

use TEST {call getTestTable}

Notes:

  • You can view the UDP messages by running the Perl script announceListen.pl.
  • Add directory \Program Files\Microsoft SQL Server\80\Tools\DevTools\Include to VC++ include dirs.
  • Add directory \Program Files\Microsoft SQL Server\80\Tools\DevTools\Lib to VC++ lib dirs.

This is a new version with the following changes:

  1. Bug fix. There was a 255 char limit on the UDP message text because I used srv_paramdata(), which has a 255 char limit. I changed the code in SQLAnnounceProc.c to use srv_paraminfo() instead. The rest of the params still have the 255 char limit.
  2. I converted the project to VS 2003.
  3. Test before use!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Rod VanAmburgh

Web Developer

United States United States

Member

I enjoy working with C#, Java, Perl and C++

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
General64-bit version PinmemberMark Nadelson10:57 17 May '07  
QuestionBug with some buffer ? PinmemberPablo755:21 31 Aug '06  
AnswerRe: Bug with some buffer ? PinmemberPablo758:06 31 Aug '06  
GeneralRe: Bug with some buffer ? PinmemberRod VanAmburgh17:34 31 Aug '06  
AnswerRe: Bug with some buffer ? PinmemberRod VanAmburgh17:29 31 Aug '06  
GeneralMS-SQL server Self join PinmemberAmit Malik19:08 25 Dec '05  
QuestionWorks great, 256 character limit? Pinmemberbertszoghy13:01 22 Apr '05  
AnswerRe: Works great, 256 character limit? PinmemberRod VanAmburgh16:54 22 Apr '05  
GeneralRe: Works great, 256 character limit? Pinmemberbertszoghy7:03 23 Apr '05  
GeneralRe: Works great, 256 character limit? Pinmemberbertszoghy2:49 25 Apr '05  
GeneralRe: Works great, 256 character limit? PinmemberRod VanAmburgh15:52 25 Apr '05  
GeneralRe: Works great, 256 character limit? PinmemberRod VanAmburgh17:31 25 Apr '05  
GeneralRe: Works great, 256 character limit? Pinmemberbertszoghy5:35 26 Apr '05  
GeneralRe: Works great, 256 character limit? PinmemberRod VanAmburgh14:37 26 Apr '05  
GeneralRe: Works great, 256 character limit? Pinmemberbertszoghy6:34 27 Apr '05  
GeneralCool PinmemberJorgeCordero17:36 3 Mar '05  
GeneralElaborate Pinmemberperlmunger5:07 7 Dec '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 25 Apr 2005
Article Copyright 2004 by Rod VanAmburgh
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid