Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment