Sometimes we in support will ask you to create a dump for when your .Net client crash due to a SqlException.
We do this in order to be able to find out more about the state of the process at the time of the crash.
So today I will show you the simplest way to create that dump with DebugDiag.
First, let us create an application that will simply connect to a database and execute a query that will run for too long and thereby cause a time out exception.
(Normally you do not know what statement is causing the exception and this one of the reasons we ask for dumps, so that we can figure this out.)
So, create a new C# console application called “TimeOutApp” as follows:
static void Main(string args)
Console.WriteLine(“Hit any key to get exception.”);
string cs = @”Data Source=<your server>;Integrated security=SSPI;Initial Catalog=<your database>”;
using (SqlConnection con = new SqlConnection(cs))
SqlCommand cmd = con.CreateCommand();
cmd.CommandTimeout = 10; // Lowering from default of 30s. to execption quicker.
cmd.CommandText = “waitfor delay ’00:00:20′;”;
and run it. This should then produce the exception:
Unhandled Exception: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
From this we can’t figure out what SQL command was executing. Of course we could trace this on server side, but that is another story. And you may not have access to the server.
So, time for some dump taking.
. Go to the download site for DebugDiag.
“Debug Diagnostic Tool v1.1”
. Download and install it on the machine that is running the crashing application.
. Start your application (“TimeOutApp” in this case).
. Start DebugDiag.
. You should now be shown a dialog called “Select Rule Type”, select “Crash” and “Next”.
. You should now be shown a dialog called “Select Target Type”, select “A specific process” and “Next”.
. You should now be shown a dialog called “Select Target”, this should list all running processes, so select your application (“TimeOutApp” in this case) and “Next”.
. You should now be shown a dialog called “Advanced Configuration”, click “Exceptions” in the “Advanced Settings” section.
. You should now be shown a dialog called “First Chance Exception Configuration”, click “Add Exception”.
. You should now be shown a dialog called “Configure Exception”. Set this up as follows.
Exception Code = E04334F4D (Just click it in the list to the left)
.Net Exception Type = System.Data.SqlClient.SqlException
Action Type = Full Userdump
Action Limit = 3 (this is so that we get more than one dump if needed).
then click OK. This should now list the added rule. So click “Save & Close”
. You should now be back at the “Advanced Configuration”, click “Next”.
. You should now be shown a dialog called “Select Dump Location And Rule Name”, change “Userdump Location” to “C:\Dumps” and click “Next”.
. You should now be shown a dialog called “Rule Completed”, select “Activate the rule now” and click “Finish”.
Now reproduce your problem (just hitting any key in the “TimeOutApp” in this case).
When the application has crashed, then the “Userdump Count” should have increased from 0.
Have a look in the “C:\Dumps” directory; this should contain files with the name looking something like this:
Compress the whole directory and upload it to us for analysis.