1 2 3 /*
4 ** Messages for "sp_listener"
5 **
6 ** 17260, "Can't run %1! from within a transaction."
7 ** 19862, "Invalid input: Server name '%1!' matches the remote instance."
8 ** 18899, "Invalid value supplied to parameter %1!."
9 ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters."
10 */11 12 /*
13 ** sp_listener cmd, addr, eng
14 **
15 ** This stored procedure is the interface to the
16 ** Dynamic Listener Daemon functionality. It allows
17 ** the sa to start, stop, suspend, resume, reserve,
18 ** network listeners on selected ports and engines.
19 ** The command will execute atomically unless the command
20 ** is reserve or the engine parameter has been specified
21 ** via the keyword remaining.
22 **
23 ** Parameters:
24 ** cmd can be any of the following:
25 ** "start", "stop", "suspend", "resume", "status",
26 ** "reserve", "activate", "unreserve"
27 ** addr can be the name of the running ASE server
28 ** or a "proto:host:port" combination.
29 ** length of addr is at the most MAXDLADDR
30 **
31 ** eng can be any list of engines including ranges such
32 ** as "1-3,5,7,10-12", or the word "remaining"
33 **
34 ** Return Value:
35 ** 0 in case of success, 1 in case of error
36 */37 createproceduresp_listener38 @cmd varchar(30)=null,39 @addr varchar(612)=null,40 @eng varchar(30)=null41 as42 43 if @@trancount > 0
44 begin45 /* 17260, "Can't run %1! from within a transaction." */46 raiserror 17260, "sp_listener"
47 return(1)48 end49 else50 begin51 set chained off52 end53 54 settransactionisolationlevel 1
55 set nocount on56 57 /* Must have sa_role as this stored procedure is related to config */58 if(proc_role("sa_role")< 1)59 return(1)60 61 /* Restrict listener command to local instance */62 if(@@clustermode = "shared disk cluster"
63 and(instance_id(@addr)isnotNULL)64 and(instance_id(@addr)!= instance_id()))65 begin66 /* 19862, "Invalid input: Server name '%1!' matches the remote instance." */67 raiserror 19862,@addr68 return(1)69 end70 71 if(@cmdin("start", "stop", "suspend", "resume", "status"))72 begin73 if(char_length(@addr)> 611)74 begin75 /*
76 ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters."
77 */78 raiserror 17325,@addr, 611
79 return(1)80 end81 dbcc listener(@cmd,@addr,@eng)82 if(@@error != 0)83 begin84 return(1)85 end86 end87 else88 begin89 print "Usage: sp_listener command [,'protocol:machine:port'[,engine]] "
90 print "sp_listener commands:"
91 print "start"
92 print "stop"
93 print "suspend"
94 print "resume"
95 print "status"
96 print "help"
97 print "The type of protocol can be one of the following: "
98 print "tcp, tli, ssltcp, ssltli, winsock, sslnlwnsck, sslwinsock"
99 print "IPV6 addresses should be enclosed in brackets, for ex 'tcp:[2001:ec8:4008:1::123]:80'"
100 print "Note: 'engine' parameter is valid only in process kernel mode"
101 end102 return(0)103 104
exec sp_procxmode 'sp_listener', 'AnyMode'
go
Grant Execute on sp_listener to public
go