Category Archives: TIP

TIP: Quickly purge SQL Server Data

I was working on writing some integration tests, and needed to quickly get the database to a clean state between them. Dropping and recreating the database would take too long, but, if I could easily delete all the data, then I could populate with what I needed for each test…with MS SQL Server, you can use the stored proc sp_MSForEachTable to run SQL against each table. The following code uses the proc, disabling triggers, and constraints so it can delete all data, then enables them again

public static void PurgeData()
	using (var conn = new SqlConnection(ConnectionString))
		var cmdText = new StringBuilder();
		cmdText.AppendLine("EXEC sp_MSForEachTable 'DISABLE TRIGGER ALL ON ?'");
		cmdText.AppendLine("EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'");
		cmdText.AppendLine("EXEC sp_MSForEachTable 'DELETE FROM ?'");
		cmdText.AppendLine("EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'");
		cmdText.AppendLine("EXEC sp_MSForEachTable 'ENABLE TRIGGER ALL ON ?'");
		using (var sqlCmd = new SqlCommand(cmdText.ToString(), conn))

Hope this helps you out.

TIP: Obliterate a file from GIT Repository (including history)

I did something stupid, and accidentally pushed some .pubxml files to a public GitHub repo that contained passwords.

I fixed up my .gitignore file, which took care of part of it, but if you viewed the history, the password were still exposed.

After much mucking about, this magical line, obliterated any trace of the file in my repo.

git filter-branch --index-filter "git rm --cached --ignore-unmatch *.pubxml" --prune-empty --tag-name-filter cat -- --all

Then this line, forced an update of the entire repo to GitHub, history and all.

git push origin --force --all

…that was a close call.

TIP: Partial screenshots made easy

I have to take partial screenshots when creating emails or documentation almost every day. I’m not a fan of installing extra tools unless they’re simple, and truly save me time. A few seconds isn’t enough. This is one of those cases, typically I’ll just take the screenshot with PrintScreen, or Alt-PrintScreen, paste it into mspaint, select and copy the part I need, and move on.

However, windows already has a tool for taking partial snapshots of the screen, it’s called “Snipping Tool“. It works for most cases, and that’s enough for me.

We just need a quick way to open it. So, hit the windows key to open the start menu and type Snipping Tool, right click on it, and select properties. Focus in Shortcut key, and hit a key combination to open it. Mac has a similar tool already bound to Cmd-Shift-4, so I bound the snippet tool to Ctrl-Shift-4.


Now, I just hit Ctrl-Shift-4, and the screen goes partially opaque. I highlight a section of the screen, and it’s automatically put in my clipboard. It’s also opened in the snipping tool, but I just close it without saving changes (Alt-F4). Then paste the partial screenshot in my email or document.


Completely remove Printer Driver

I recently had to keep retesting an installer, part of it’s actions were to install a print driver, but to be able to keep testing, I had to remove the driver from the computer, not just the printer. So, here’s how it’s done, in case someone else needs to do this.

  1. Find your driver name. (ex.“Brother MFC-J6520DW Printer”)
  2. In “Devices and Printers” remove all printers using the driver from step 1
  3. Open Regedit.
  4. Navigate to (on 32 bit(x86) computers) “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3”
  5. Or (on 64 bit(x64) computers) “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3”
  6. And then remove the folder that matches the printer driver name.
  7. Open Services, and restart the print spooler service

That’s it.

TIP: Always run Visual Studio as an Administrator

If you’re like me, you always want Visual Studio opening as Administrator, allowing it to install services, and do whatever you need it to do. But you often forget to right click and “Run as Administrator”. Or you just want to be able to use the pinned shortcuts on the task bar. It’s really amazingly simple to make it always run as an administrator, just follow these simple steps:

  1. Right Click on “devenv.exe” in Explorer
  2. ClickTroubleshoot compatibility
  3. ClickTroubleshoot program
  4. CheckThe program requires additional permissions
  5. ClickNext
  6. ClickTest the program…“. It should launch Visual Studio as Administrator
  7. ClickNext
  8. ClickYes, save these settings for this program
  9. ClickClose the troubleshooter

You can revert by following the same steps, but unchecking “The program requires additional permissions”