Skip to main content

Posts

Showing posts from November, 2013

Getting started with ELMAH and ASP.NET MVC

We all need a framework to log exceptions in our web application. Today, We are going to learn about same. ELMAH(Error Logging Modules and Handlers) is an application wide error logging framework. How we can install it in ASP.NET MVC.

What is ELMAH:
ELMAH(Error logging Modules and Handlers) is an application wide error logging facility that is an pluggable framework. It can dynamically added to running an ASP.NET application. You also have Nuget package for the same.
You can find more information about on following link.

https://code.google.com/p/elmah/

Once you install ELMAH, You can have following advantages
You can log almost all unhandled exceptions in the system.An RSS feed of last 15 errors from the logAn email notification of each error occurs.A remote web page to log all the exceptions.You can insert log a various locations like files text file, SQL Server, Oracle etc.
ELMAH NuGet Package:
There is a nuget package also available for ELMAH. You can find at following link.

http:/…

How to find days in year except Saturday and Sunday in C#

Before 2 years I have written a blog post to find Saturday and Sunday in given date range.  It has gain a lot of popularity and on that blog post one user ask about how we can find days in year except Saturday and Sunday in C#. This post is a in reply for that. Following is a code for that.
using System; namespace DatimeApplication { class Program { static void Main(string[] args) { DateTime startDate = new DateTime(2013, 1, 1); DateTime endDate = new DateTime(2013, 12, 31); TimeSpan diff = endDate - startDate; int days = diff.Days; int j=0; for (var i = 0; i <= days; i++) { var testDate = startDate.AddDays(i); if (testDate.DayOfWeek != DayOfWeek.Saturday && testDate.DayOfWeek != DayOfWeek.Sunday) { j = j + 1; Console.WriteLine(testDate.ToShortDateString()); } …

My visual studio settings

Lots of people send me email about what kind of visual studio settings I am using and I am replying them again and again so I thought it will be good idea to write a blog post about it.

Yes, Since last 2 months I have been using dark theme of Visual Studio 2012 but I am not using default dark theme color settings of visual studio. I’m using dark theme color settings created by Keith Elder. You can find more information about color settings of this theme from following link.

http://keithelder.net/2010/03/05/my-visual-studio-color-settings-again/

I simply love this one and its works on all flavours of Visual Studio starting from Visual Studio 2008 to 2012. Below are few screenshots from that.



Here is another screenshot.



It’s been great for eyes and I can work with very easily and as you may notice my default font for visual studio is Consolas and size is 11.

Now lots of people ask me whether its working fine with resharper or not and Its works like a charm. See following screenshot.



And…

How to find space used by table in SQL Server

Recently there was requirement for a client where we need to find space occupied/used  by particular table in SQL Server. I did some research a found a very cool way to get space used information from SQL Server.

With SQL server 2005 and higher version you can use ‘sp_spaceused’ to find space used by table in SQL Server.

Following is a syntax for that.
sp_spaceused N'YourTableName'

You can find more information about it from the following link.
http://msdn.microsoft.com/en-us/library/ms188776.aspx

When you run this in SQL Server, Its displays Number of Rows, disk space served and disk space used by a table or indexed view and also displays disk space reserved and used by database.



Here in the above example, You have seen that I have used to find space for employee table in my blog sample database and its providing information about rows, reserved space, data size, index_size space and unused space.

That’s it. Hope you like it. Stay tuned for more.

How to find path of database data files and log files in SQL Server

In this post, We will learn about different technique to find path of data files and log files on SQL Server. Let’s go through one by one of them.

The first technique, We are going to use is very simple way to finding file path for database. But with this you can find path for one database only. It’s very simple, Select database on object explorer and right click and select properties.




Now once you click on properties a dialog box appear like following. Select files and go to path column it will show path of database data files and log files.


Now we will learn another technique where we can find database data file and log file path from query. Below is query for that.

SELECT name, physical_name FROM sys.master_files where database_id= db_id('blog')
Now once you run this query it will load result like following.




That’s it you can find you database file path very easily. You can use above query to find files path for multiple databases also without using where clause. Hope you lik…