1

I have an ASP.NET web application written with C#. It uses SQL Server 2008 database. It seems that some of the SQL queries are deadlocking the SQL server and I'm also experiencing bad SQL Server performance. To find out which, I thought to add a diagnostic event logging, but I'm not sure how. If I was writing a plain Windows application, I'd do that with the Windows Event Log, or with just a simple text file. So I'm curious, how to do the same from a web application?

RandomUs1r
  • 4,010
  • 1
  • 24
  • 44
c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • 1
    for the issue of dead lock, this might help you [http://stackoverflow.com/questions/12422986/sql-query-to-get-the-deadlocks-in-sql-server-2008][1] [1]: http://stackoverflow.com/questions/12422986/sql-query-to-get-the-deadlocks-in-sql-server-2008 – Singleton Mar 01 '13 at 22:01
  • added a sql server tag for you. – RandomUs1r Mar 01 '13 at 22:23

3 Answers3

3

There are many options for logging from an ASP.Net web application.

NLog is one worthy of consideration because it performs well and offers a wide range of log targets based on severity including text file, database, email, or a GUI log viewer such as Sentinel.

Having said that, application-level logging is probably not the best way to diagnose specifically SQL Server deadlocks. I would suggest starting with SQL Server Profiler for that task

Analyzing Deadlocks with SQL Server Profiler

Eric J.
  • 147,927
  • 63
  • 340
  • 553
1

.NET has build in loggin system with rich features and flexible configuration since version 2.0. You can start with this article on MSDN For some reason most people do not use it though and prefer either Log4net or NLog for logging. First is port of java logging tool and second is rethinking of it. I personally prefer to use TraceSource with filters. ADO.NET natively support it as well.

vittore
  • 17,449
  • 6
  • 44
  • 82
  • Good deal. Where is that built-in log saved -- file system file, or database? – c00000fd Mar 01 '13 at 22:01
  • @c00000fd wherever you configure it to be saved. Here is information on listeners http://msdn.microsoft.com/en-us/library/4y5y10s7.aspx – vittore Mar 01 '13 at 22:02
  • IMHO the built-in logging framework lacks the completeness of a solution like NLog or Log4Net. – Eric J. Mar 01 '13 at 22:20
  • @EricJ. can you give an example ? – vittore Mar 02 '13 at 00:13
  • Example: What do you have to do to with the built-in frameworks to write Critical & error items to a text file, database and email address; warning items to a text file & database, and other items just to a text file, but for the debug build also write everything to a GUI based viewer to facilitate development? With NLog it's just a few lines of configuration. – Eric J. Mar 02 '13 at 00:36
  • @EricJ well basically you can create several listeners and configure them for different alert levels. Well you can create listeners for both email and db, however I found it more usefull just to go to event viewer and configure stuff like that their and let app just to it's own text logs and/or event viewer and/or console etc. – vittore Mar 02 '13 at 20:42
  • Exactly... you can create. Listeners for those targets and many others are already available out of the box for NLog (and I thing for log4net too). The solutions are simply more complete, and provide more of what one needs in a production environment. – Eric J. Mar 03 '13 at 05:08
0

Deadlocking occurs on the SQL side, it's impossible for ASP.NET to be aware of the full picture.

I recommend checking your queries for a WITH LOCK statement and before removing it figuring out why it's there to begin with.

Otherwise, if you find an offending query via SQL server Diagnostics manager... or if you can reproduce the deadlock purely on the SQL side, add WITH NOLOCK to that query. T

his is by far the simplest solution, better solutions involve getting to the root cause of why the deadlock is occurring in the first place.

RandomUs1r
  • 4,010
  • 1
  • 24
  • 44