的Connection.close()和connection.Dispose()之间的区别是什么? [英] What is the difference between connection.Close() and connection.Dispose()?
本文介绍了的Connection.close()和connection.Dispose()之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注意到,在 System.Data.SQLite
的 SQLiteConnection
对象拥有两个类似的方法:
I noticed that the SQLiteConnection
object in System.Data.SQLite
owns two similar methods :
-
关闭()
-
的Dispose()
Close()
Dispose()
同为 SQLiteDataReader
对象。
有什么区别?
推荐答案
处置
也将关闭,如果它没有被关闭了连接,但打电话时关闭
,您可以再次重新打开连接。这是不可能的,当连接配置。
Dispose
also closes the connection if it hasn't been closed, but when calling Close
, you can reopen the connection again. This is not possible when the connection is disposed.
在一般情况下,不叫关闭
,而只是调用由包装建立在使用$ C连接的处理含蓄$ C>块:
In general, don't call Close
, but simply call dispose implicitly by wrapping the creation of a connection in a using
block:
using (var connection = new SqlConnection(...))
{
// use connection here.
} // connection gets closed and disposed here.
这篇关于的Connection.close()和connection.Dispose()之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文