This is something I has been always wonder.... will it?
Because whenever I write code to use DB connection, I always somehow have to ensure is closed before process to next piece.
But when if the I have a ChildWindow that open a connection in its constructor and not close it until it hits the Save Button or Cancel Button. Then if the whole Application got closed, will the DB connection close instantly? Or it has to wait for the timeout and will close automatically?
EDIT:
So I am trying to keep a live connection open for logging all errors on my application:
public App()
{
ErrorHelper errorHelper = new ErrorHelper(); // Will open DB connection
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(currentDomain_UnhandledException);
}
/// <summary>
/// For catch all exception and put them into log
/// </summary>
void currentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
errorHelper.WriteError(e.ExceptionObject as Exception);
}
Because I don't like how I open connection everytime log a single error, so I want to keep connection open all the time. This is similar as the OP I was describe. In this situration, it keeps connection open all the time. But will the DB connection close instantly after it exits?