Reputation: 22255
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?
Upvotes: 1
Views: 1416
Reputation: 4190
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.
Upvotes: 0
Reputation: 17579
.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.
Upvotes: 1
Reputation: 150108
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
Upvotes: 3