正确关闭 vb.net 中的 adodb 连接

发布于 2024-11-02 12:16:57 字数 1226 浏览 1 评论 0原文

在vb.net中,有一些应用程序使用adodb来访问mysql服务器。

private adoconnect as new adodb.connection
public adors as new adodb.recordset

public function returnadors(byval column as string) as string
 return adors.fields(column).value.tostring
end function


Public Function ReadData(ByVal strQuery As String, Optional ByVal strWhere As String = vbNullString) As Boolean

        Try

            If ADOConnect.State = ConnectionState.Open Then Call CloseConnection()
            ADOConnect.Open(dsn, user, pass)
            ADORS.Open(strQuery, ADOConnect, ADODB.CursorTypeEnum.adOpenDynamic)
            If not ADORS.EOF  Then Return True

        Catch ex As Exception

            msgbox(ex)

        End Try

        Return False

End Function

public sub closeconnection()
   if adoconnect.state = connectionstate.open then adoconnect.close
end sub

现在假设我们想用数据库中的内容填充文本框:

if readdata("SELECT NAME FROM USERS WHERE ID = 1") then
    me.textbox1.text = returnadors("NAME")
end if
call closeconnection

重新编写这些函数是一项艰巨的任务 - 除非绝对需要,否则我对这样做不感兴趣。

这是我的问题。

即使连接关闭(并且我已单步执行代码,它也会关闭) 连接在处于睡眠状态的sql server上仍然可见,

为什么?我怎样才能确保连接已关闭。

谢谢

in vb.net, there are some applications that use adodb to access a mysql server.

private adoconnect as new adodb.connection
public adors as new adodb.recordset

public function returnadors(byval column as string) as string
 return adors.fields(column).value.tostring
end function


Public Function ReadData(ByVal strQuery As String, Optional ByVal strWhere As String = vbNullString) As Boolean

        Try

            If ADOConnect.State = ConnectionState.Open Then Call CloseConnection()
            ADOConnect.Open(dsn, user, pass)
            ADORS.Open(strQuery, ADOConnect, ADODB.CursorTypeEnum.adOpenDynamic)
            If not ADORS.EOF  Then Return True

        Catch ex As Exception

            msgbox(ex)

        End Try

        Return False

End Function

public sub closeconnection()
   if adoconnect.state = connectionstate.open then adoconnect.close
end sub

now lets say we wanted to populate a textbox with something from the database:

if readdata("SELECT NAME FROM USERS WHERE ID = 1") then
    me.textbox1.text = returnadors("NAME")
end if
call closeconnection

re writing these functions is a big task - and I am not interested in doing it unless absolutely needed.

Here is my problem though.

even if the connection is closed (and i have stepped through the code, it closes)
The connection is still visible on the sql server in a sleep state

why? and how can i make sure that the connection is closed.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青春如此纠结 2024-11-09 12:16:57

将以下内容添加到您的 ConnectionString 中:

Pooling=False;

Add the following to your ConnectionString:

Pooling=False;
攀登最高峰 2024-11-09 12:16:57

我对你正在做的事情没有太多经验,但这通常是我使用 sqlserver 连接所采取的路径。 使用将自动关闭您的连接。

Using ADOconnect
   'operations
End Using

I don't have much experience with exactly what you are doing, but this is usually the path I take with sqlserver connections. Using will automatically close your connection.

Using ADOconnect
   'operations
End Using
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文