1 2 3 /*
4 ** Messages from freedll
5 **
6 ** 17260, "Can't run %1! from within a transaction."
7 ** 17240, "'%1!' is not a valid name."
8 ** 18393, "DLL for the extended stored procedure '%1!' is not found."
9 ** 18392, "sp_freedll failed."
10 */11 12 createproceduresp_freedll13 @dll_name varchar(259)/* dll name (which may
14 include extension) */15 as16 17 18 /*
19 ** If we're in a transaction, disallow this since it might make recovery
20 ** impossible.
21 */22 if @@trancount > 0
23 begin24 /*
25 ** 17260, "Can't run %1! from within a transaction."
26 */27 raiserror 17260, "sp_freedll"
28 return(1)29 end30 31 set chained off32 33 settransactionisolationlevel 1
34 /* check if user has sa role, proc_role will also do auditing
35 ** if required. proc_role will also print error message if required.
36 */37 38 if(proc_role("sa_role")= 0)39 return(1)40 41 /*
42 ** Remove optional . and extension (.dll or .so) from @dllname
43 */44 declare@dotposition int
45 select@dotposition= patindex("%.%",@dll_name)46 if(@dotposition> 0)47 select@dll_name= substring(@dll_name, 1,@dotposition- 1)48 49 /*
50 ** Check to see that the @dll_name is valid.
51 */52 53 if valid_name(@dll_name, 255)= 0
54 begin55 /*
56 ** 17240, "'%1!' is not a valid name."
57 */58 raiserror 17240,@dll_name59 return(1)60 end61 62 /*
63 ** Make sure the dll exists.
64 */65 if(notexists(select*66 fromsysobjects o
67 where getdllname(o.id)=@dll_name68 ando.type= 'XP'
69 and(o.sysstat& 15)= 4))70 begin71 /*
72 ** 18393, "DLL for the extended stored procedure '%1!' is not found."
73 */74 raiserror 18393,@dll_name75 return(1)76 end77 78 /*
79 ** Now unload the DLL.
80 */81 dbcc spfreedll(@dll_name)82 83 if(@@error != 0)84 begin85 /*
86 ** 18392, "sp_freedll failed."
87 */88 raiserror 18392
89 return(1)90 end91 92 return(0)93
exec sp_procxmode 'sp_freedll', 'AnyMode'
go
Grant Execute on sp_freedll to public
go