SQL Server Developer Center > SQL Server Forums > SQL Server SMO/DMO > Error produced when executing database.truncatelog
Ask a questionAsk a question
 

AnswerError produced when executing database.truncatelog

  • Monday, October 26, 2009 3:34 PMjwbutler123 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I recently upgraded from sql 2005 to sql 2008.  I had a routine to truncate the log using the database.truncatelog method.  But now when I run the following code I get the following error.  Books on line does not indicate that the method should not be used on 2008 databases.  Note:  The database was detched from a 2005 sql instance and attached to a sql 2008 instance.  Any ideas?
    db.Shrink(0, ShrinkMethod.Default)
    db.TruncateLog()
    
    

    Error:

    Microsoft.SqlServer.Management.Smo.UnsupportedVersionException: This method or property is accessible only while working against a version earlier than SQL Server 2008.

    Thanks,
    John

Answers

  • Thursday, October 29, 2009 7:37 PMSREEKAR MMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello John TruncateLog() method in Database object is not supported from SQL Server 2008 onwards. The other alternative is to use set the Recovery Model of the database to SIMPLE and execute DBCC SHRINKFILE

    ALTER DATABASE db SET RECOVERY SIMPLE
    go
    DBCC SHRINKFILE(shrinkdemo_log)
    go

    In SMO

    db.RecoveryModel = RecoveryModel.Simple.;
    db.Alter();
    db.LogFiles[0].Shrink(0,ShrinkMethod.TruncateOnly);

    -Sreekar
    • Marked As Answer byjwbutler123 Thursday, October 29, 2009 8:30 PM
    •  

All Replies

  • Thursday, October 29, 2009 7:37 PMSREEKAR MMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello John TruncateLog() method in Database object is not supported from SQL Server 2008 onwards. The other alternative is to use set the Recovery Model of the database to SIMPLE and execute DBCC SHRINKFILE

    ALTER DATABASE db SET RECOVERY SIMPLE
    go
    DBCC SHRINKFILE(shrinkdemo_log)
    go

    In SMO

    db.RecoveryModel = RecoveryModel.Simple.;
    db.Alter();
    db.LogFiles[0].Shrink(0,ShrinkMethod.TruncateOnly);

    -Sreekar
    • Marked As Answer byjwbutler123 Thursday, October 29, 2009 8:30 PM
    •  
  • Thursday, October 29, 2009 8:32 PMjwbutler123 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks for taking the time.  It worked like a champ...