如何关闭在asp.net中的SQLConnection [英] how to close a sqlconnection in asp.net
问题描述
我想知道是否有什么问题在这个asp.net code:
i would like to know if there's something wrong in this asp.net code:
mydatareader = mycmd.executeReader()
if myDataReader.HasRow then
// Do something
end if
myConnection.Close()
如果我避免所谓的MyDataReader.Close()做连接紧密呢?
我问这个,因为我假设,如果所谓的MyConn.Close,它会自动关闭关联的DataReader ......还是我错了?
If i avoid to call a "MyDataReader.Close()" does the connection close anyway ? I ask this because i'm assuming that if call a "MyConn.Close" it automatically close the associated datareader... or am i wrong ?
感谢
推荐答案
您必须关闭你的读者,而不是关闭的连接。看看这里:
的http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.close.aspx
You have to close your reader instead of closing the connection. Have a look here: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.close.aspx
这篇关于如何关闭在asp.net中的SQLConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!