Created
November 6, 2010 21:46
-
-
Save gorsuch/665729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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