Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Dear all,

How to decrease size of the .ldf file (ldf log in sql 2008) in c#. No script, how to make to code in c#.

Thanks for all
Posted
Comments
ZurdoDev 13-Feb-14 21:13pm    
Your code will have to execute script.

If I understand your question then decreasing size of LDF file through C# code is not doable.

Reason: LDF file is getting generated by database instance. This transaction logs file's format is getting maintain by SQL server instance. This is like, can you reduce size of PDF file, Doc file through just C# code without any vendor component.

Yes for sure you can write a program which connects to database instance and can perform below actions.

C#
SQLDatabase.TransactionLog.Truncate();
SQLDatabase.Shrink(5, SQLDMO.SQLDMO_SHRINK_TYPE.SQLDMOShrink_NoTruncate);
SQLDatabase.TransactionLog.Truncate();
SQLDatabase.Shrink(5, SQLDMO.SQLDMO_SHRINK_TYPE.SQLDMOShrink_Default);



If you are decreasing file size to archiving it then simply write a program to Zip (Compress) it, it will work and will be easy also.

-- Thanks Rushi
 
Share this answer
 
Hi Rushi and thanks for your solution, but when put this code, make the error:
{"This method or property is only accessible to work with an earlier version a SQL Server 2008."} System.Exception {Microsoft.SqlServer.Management.Smo.UnsupportedVersionException}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900