SQL Tricks

Delete all tables EXEC sp_MSforeachtable @command1 = “DROP TABLE ?”  Grant execute permissions to all stored procedures to a specific user CREATE PROC grantexecutepermission( @UserName NVARCHAR(250)) AS DECLARE curse CURSOR  FOR SELECT name FROM   sysobjects WHERE  TYPE = ‘P’ OPEN curse DECLARE  @proc VARCHAR(100) DECLARE  […]

Impersonation in Microsoft Dot Net

Usage string domain = “ExampleDomain”; string userName = “ExampleUserName”; string password = “ExamplePassword”; using (Impersonation impersonation = new Impersonation(domain, userName, password)) { // impersonation occuring in here Console.WriteLine(System.Security.Principal.WindowsIdentity.GetCurrent().Name); } Implementation using System; using System.Runtime.InteropServices; using […]