这是我一直想知道的事情....会吗?当应用程序关闭时,数据库连接会立即关闭吗?
因为每当我编写代码使用DB连接时,我总是不得不保证在处理之前关闭下一个块。
但是当,如果我有一个开在其构造连接,直到它击中保存按钮不会关闭或取消按钮ChildWindow。那么如果整个应用程序关闭了,数据库连接会立即关闭吗?或者它必须等待超时并自动关闭?
编辑:
所以我想保持实时连接打开登录我的应用程序的所有错误:
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);
}
因为我不喜欢我怎么打开连接,每次登录一个错误,所以我想保持连接一直打开。这与我描述的OP相似。在这种情况下,它始终保持连接。但数据库连接在退出后会立即关闭吗?
@Oded,我没有看到关于现有应用程序的行为的任何假设。 – mikerobi 2012-03-21 19:56:11
@按要求提供,我推出了一些我正在研究的内容。但正如mikerobi所说,我想知道退出应用程序的行为。没有解决方法来确保连接关闭。 – 2012-03-21 20:05:42