Blog from a software professional, Passionate to work in latest cutting edge technologies in order to get better results in business.
Friday, February 13, 2009
SQL Server: How to reduce LDF file size
I use SQL Server 2005 in my development server and the Database files (.MDF & .LDF) were in C drive. As we were working on the development the LDF (Transaction log files) increased drastically.
So i thought its times to reduce it or later it might make the system slow or space crunch would be there.
The tried following options to reduce the LDF file:
1. Right click on Database -> Tasks -> Shrink -> Files -> Choose File type : Log > Selected Shrink action : Release unused space & later Reorganize pages, Both did not help as the log was more than 1 GB whihc is not so much because i have seen some people had it more 40 GB when log file was not monitored frequently.
2. Used DBCC shrinkfile some time before, which was also not helpful.
Then found from the forums & did the following which worked:
Steps:
1. Make the database offline.
2. Right click & did 'Detach...' for the respective database.
3. Went to the file system where the LDF file resides and moved to a safer place.
4. Then on databases folder (below the Server icon), did right click & clicked Attach.
5. In Attach database window, selected the database & attached it without LDF file. So that system automatically created a new one which is of very small size :)
Thus the issue was solved. I believe there are other options as well to reduce LDF files,
If you are aware of any other options feel free to write it down :)
[Update: July 12 2009]
Now there seems to be much more easier way to reduce LDF file :)
http://mohammedfauzi.blogspot.com/2009/07/moss-sharepointconfig-ldf-file-grows.html
Thanks
Fauzi
Tuesday, October 7, 2008
Common Method to Log Exception - C#
As per friend's request i am posting the code for a common method to log the exceptions which may occur in you application;
We can place this code in one of your common classes and call this method from the Catch block passing the exception object as its parameter.
Following is the code;
public void logException(Exception ex)
{
string strMethodName = ex.TargetSite.Name;
string strClassName = ((System.Reflection.MemberInfo)(ex.TargetSite)).ReflectedType.Name;
string strErrLineNo = ex.StackTrace;
srWriterObj.NewLine = ("\r\n");
srWriterObj.WriteLine ("Error: " + ex.Message + " on " + System.DateTime.Now.ToString());
srWriterObj.NewLine = ("\r\n");
srWriterObj.WriteLine("MethodName: " + strMethodName + " | " + "ClassName: " + strClassName + " | " + "ErrLineNo: " + strErrLineNo);
srWriterObj.Flush();
srWriterObj.Close();
}
Just create the object of the class and call your exception method as shown below to log exceptions;
catch (Exception ex)
{
GServices objGServices = new GServices();
objGServices.logException(ex);
}
Note: Additional Namespace to be added for the above code are System.Reflection and System.IORegards
Mohammed Fauzi ~ 4Z