尝试在.NET中关闭SqlConnection时为什么会出现ThreadAbortException?

Den*_*nis 8 .net c# vb.net

我这样做时会一直遇到以下异常:

Using cnn As SqlConnection = New SqlConnection(ConnectionStr)
    cnn.Open()  'I am fine up to here'
End Using       'Here I am getting the following exception'
Run Code Online (Sandbox Code Playgroud)

手动调用cnn.Dispose()会导致相同的异常.在我的代码中的大多数地方似乎都可以,但只是在这个函数中,我无法关闭我打开的连接,因为我不断收到ThreadAbortException.我很难过,有什么想法吗?任何提示?这是我得到的例外:

System.TypeInitializationException: The type initializer for 'System.Data.ProviderBase.DbConnectionClosedPreviouslyOpened' threw an exception. ---> System.Threading.ThreadAbortException: Exception of type 'System.Threading.ThreadAbortException' was thrown.
   --- End of inner exception stack trace ---
   at System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlInternalConnection.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Close()
   at System.Data.SqlClient.SqlConnection.Dispose(Boolean disposing)
Run Code Online (Sandbox Code Playgroud)

Den*_*nis 1

有人提出了一个可怕的“Finalize”方法。它不断触发并尝试关闭连接。就这样浪费了几个小时!!!有一天我将摆脱代码中的所有 Finalize 方法 - 在那之前 - 忍住吧!