Application_Error() not firing
<p>I'm trying to run an ASP.NET application that logs exceptions to the database. I'm using Application_Error to catch the exception.</p>

<p>Before adding the connection string, just to test my code (Logger class and the code in Global.asax), I tried to log the error to windows event viewer. This works as expected.</p>

<p>But after adding the connection string to the Web.config file and adding the ADO.NET code, I tried to run the application. But I get the yellow screen of death :D</p>

<p>I don't know what is wrong with my code. I only modified the connectionStrings element in the Web.config file and added the ADO.NET code.</p>

<p>Here is the code.</p>

<p>This is the web form code in the Page_Load event. The Countries.xml file is not present and it is expected to throw an error.</p>

<pre><code>DataSet dataset = new DataSet();
dataset.ReadXml(Server.MapPath("~/Countries.xml"));
GridView1.DataSource = dataset;
GridView1.DataBind();
</code></pre>

<p>Application_Error</p>

<pre><code>Exception exception = Server.GetLastError();
if (exception != null)
{
Logger.Log(exception);
Server.ClearError();
Server.Transfer("~/Errors.aspx");
}
</code></pre>

<p>Web.config</p>

<pre><code>&lt;configuration&gt;
&lt;connectionStrings&gt;
    &lt;add name="DBCS" connectionString="Data Source=.;database=Sample;Integrated Security=SSPI" providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
&lt;system.web&gt;
&lt;compilation debug="true" targetFramework="4.5.2" /&gt;
&lt;/system.web&gt;
&lt;/configuration&gt;
</code></pre>

<p>I tried debugging by placing a breakpoint at the Application_Error method in Global.asax, but the control never reaches to that point.
The exception is triggered from the Page_Load event.
There are no compilation errors in the Logger class code.
Also, I don't want to use the customErrors route to solve this problem.</p>

<p>Thanks in advance.</p>

<p>This is the link to the code:
<a href="https://drive.google.com/folderview?id=0B5K22Q9r50wXU0VOQmJKVHBoaDg&amp;usp=sharing" rel="noreferrer">https://drive.google.com/folderview?id=0B5K22Q9r50wXU0VOQmJKVHBoaDg&amp;usp=sharing</a></p>