VB and VBA Users Source Code: Net Send the users of a Database (SQL Server)
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Net Send the users of a Database (SQL Server)
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, April 30, 2001
Hits:
632
Category:
Database/SQL/ADO
Article:
The following script creates a stored procedure which Net Send's all the users of the specified database with a message: --Written for SQL Server CREATE PROCEDURE NetSendUsers ( @DatabaseName VARCHAR(50), @Message VARCHAR(200) ) AS DECLARE @ToSend VARCHAR(25) DECLARE @NetSend VARCHAR(255) DECLARE usercursor SCROLL CURSOR FOR SELECT DISTINCT S.hostname FROM master..sysprocesses S, master..sysdatabases D WHERE S.dbid=D.dbid AND D.Name =@DatabaseName GROUP BY S.hostname, D.Name OPEN usercursor FETCH FIRST FROM usercursor INTO @ToSend WHILE(@@FETCH_STATUS=0) BEGIN PRINT @ToSend SELECT @NetSend = 'master..xp_cmdShell "NET SEND ' + @ToSend + ' ' + @Message + '"' EXEC(@NetSend) FETCH NEXT FROM usercursor INTO @ToSend END CLOSE usercursor DEALLOCATE usercursor GO
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder