Skip to content

Instantly share code, notes, and snippets.

@gorsuch
Created November 6, 2010 21:46
Show Gist options
  • Save gorsuch/665729 to your computer and use it in GitHub Desktop.
Save gorsuch/665729 to your computer and use it in GitHub Desktop.
using System;
using Microsoft.SqlServer.Management.Smo;
namespace LogTruncate
{
class Program
{
static void Main(string[] args)
{
Server server = new Server(@"dbserver\instancename");
foreach (Database db in server.Databases)
{
try
{
if (!db.IsSystemObject)
{
Console.WriteLine(db.Name);
db.RecoveryModel = RecoveryModel.Simple;
db.Alter();
foreach (LogFile logfile in db.LogFiles)
{
logfile.Shrink(1, ShrinkMethod.Default);
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment