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.
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”
What more is there to say? Microsoft opensourced Roslyn (.NET Compiler Platform), source is avaiable on CodePlex!!!
It’s fantastic news, to quote Eric Lippert
What astonished me was that its not just a “reference” license, but a full on liberal Apache 2.0 license. And then to have Miguel announce that Xamarin had already got Roslyn working on linux was gobsmacking.
It’s a huge step, and something I hope Microsoft does more of. I can’t wait to find some time to dig into this code, and see how it all works.