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.
This can be done simply through SQL Server Management Studio 2012
- Right click on the “Databases” folder under your server and select “Import Data-tier Application…”
- Hit “Next” to get past the intro
- Select “Import from Windows Azure”
- Pick your storage account, container, file, etc
- Click Next
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.
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.
Shift-Right click a folder in windows explorer and tada!
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.
- Find your driver name. (ex.“Brother MFC-J6520DW Printer”)
- In “Devices and Printers” remove all printers using the driver from step 1
- Open Regedit.
- Navigate to (on 32 bit(x86) computers) “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3”
- Or (on 64 bit(x64) computers) “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3”
- And then remove the folder that matches the printer driver name.
- Open Services, and restart the print spooler service
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:
- Right Click on “devenv.exe” in Explorer
- Click “Troubleshoot compatibility”
- Click “Troubleshoot program”
- Check “The program requires additional permissions”
- Click “Next”
- Click “Test the program…“. It should launch Visual Studio as Administrator
- Click “Next”
- Click “Yes, save these settings for this program”
- Click “Close the troubleshooter”
You can revert by following the same steps, but unchecking “The program requires additional permissions”