This is what I always asked myself a question ... isn't it?
Because whenever I write code to use a database connection, I always somehow have to be closed before the process to the next part.
But if I have a ChildWindow that opens a connection in its constructor and does not close it until it clicks the "Save" or "Cancel" button. Then, if the entire application is closed, will the DB connection occur immediately? Or should he wait for a timeout and will automatically close?
EDIT:
So, I am trying to keep an open connection open to log all errors in 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 the way I open the connection every time, logging one error, so I want to constantly open the connection. This is similar to the OP that I described. In this application, he constantly maintains a connection. But will there be a DB connection immediately after it leaves?
King chan
source share