日期:2014-05-18  浏览次数:20439 次

关于数据库的连接关闭的一个问题~~
数据库连接以后, 调用 DataConnection.Close()关闭连接,然后 DataConnection = Nothing 
请问 如果只有一句 DataConnection = Nothing , 不close()掉可以吗 ?它俩的作用是一样的吗?
 
Public Sub Kill()
  Call KillAllCommands()

  myCommandStatus = Nothing

  If Not IsNothing(DataConnection) Then
  Call DataConnection.Close()
  Call DataConnection.Dispose()
  DataConnection = Nothing
  End If

  If Not IsNothing(ADOConnection) Then
  ADOConnection = Nothing
  End If
  End Sub



------解决方案--------------------
Call DataConnection.Close()
Call DataConnection.Dispose()即可
------解决方案--------------------
如果只有一句 DataConnection = Nothing ,不会立即关闭....
------解决方案--------------------
设置为Nothing是不行的,因为数据连接包含非托管资源,不会自动回收,还是应该Close掉。