1 2 3 /*
4 ** Messages from addextendedproc
5 **
6 ** 17260, "Can't run %1! from within a transaction."
7 ** 18388, "You must be in the master database to run %1!"
8 ** 17240, "'%1!' is not a valid name."
9 ** 18387 "addextendedproc failed. Check the server error log file."
10 */11 12 createproceduresp_addextendedproc13 @esp_name varchar(255),/* esp name */14 @dll_name varchar(259)/* dll name (which may
15 include extension) */16 as17 18 19 /* If we're not in the master database, disallow addextendedproc */20 21 if db_name()!= "master"
22 begin23 /*
24 ** 18388, "You must be in the master database in order to run %1!
25 */26 raiserror 18388, "sp_addextendedproc"
27 return(1)28 end29 30 /*
31 ** If we're in a transaction, disallow this since it might make recovery
32 ** impossible.
33 */34 if @@trancount > 0
35 begin36 /*
37 ** 17260, "Can't run %1! from within a transaction."
38 */39 raiserror 17260, "sp_addextendedproc"
40 return(1)41 end42 43 set chained off44 45 settransactionisolationlevel 1
46 /* check if user has sa role, proc_role will also do auditing
47 ** if required. proc_role will also print error message if required.
48 */49 if(proc_role("sa_role")= 0)50 return(1)51 52 /* check that esp_name is a valid identifier */53 if valid_name(@esp_name, 255)= 0
54 begin55 /*
56 ** 17240, "'%1!' is not a valid name."
57 */58 raiserror 17240,@esp_name59 return(1)60 end61 62 /* can't check that dll_name is valid since it might
63 ** include .syntax, so check length only:
64 */65 if char_length(@dll_name)> 255
66 begin67 /*
68 ** 17240, "'%1!' is not a valid name."
69 */70 raiserror 17240,@dll_name71 return(1)72 end73 74 75 dbcc addextendedproc(@esp_name,@dll_name)76 77 if(@@error != 0)78 begin79 /*
80 ** 18387, "sp_addextendedproc failed."
81 */82 raiserror 18387
83 return(1)84 end85 86 return(0)87 88
exec sp_procxmode 'sp_addextendedproc', 'AnyMode'
go
Grant Execute on sp_addextendedproc to public
go