Guest User

Untitled

a guest
Jun 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. using System;
  2. using Microsoft.SqlServer.Management.Smo;
  3.  
  4. namespace LogTruncate
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. Server server = new Server(@"dbserver\instancename");
  11. foreach (Database db in server.Databases)
  12. {
  13. try
  14. {
  15. if (!db.IsSystemObject)
  16. {
  17. Console.WriteLine(db.Name);
  18. db.RecoveryModel = RecoveryModel.Simple;
  19. db.Alter();
  20. foreach (LogFile logfile in db.LogFiles)
  21. {
  22. logfile.Shrink(1, ShrinkMethod.Default);
  23. }
  24. }
  25. }
  26. catch (Exception e)
  27. {
  28. Console.WriteLine(e.Message);
  29. }
  30. }
  31. }
  32. }
  33. }
Add Comment
Please, Sign In to add comment