分数不多了,想请教老大们几个问题,数据库的
Public Sub SQLExt(StrSql As String)
Dim cmd As New ADODB.Command
Connect
Set cmd.ActiveConnection = Conn
cmd.CommandText = StrSql
cmd.Execute
Set cmd = Nothing
Disconnect
End Sub
Public Function QueryExt(ByVal StrSql As String) As ADODB.Recordset
Dim Rs As New ADODB.Recordset
Connect
Set Rs.ActiveConnection = Conn
Rs.CursorType = 1
Rs.LockType = 1
Rs.Open StrSql
Set QueryExt = Rs
End Function
Public Sub Connect()
If IsConnect = True Then
Exit Sub
End If
Set Conn = New ADODB.Connection
Conn.ConnectionString = Cnn
Conn.Open
If Conn.State <> adStateOpen Then
MsgBox "数据库连接失败!", vbOKOnly + vbCritical, "警告"
End
End If
IsConnect = True
End Sub
Public Sub Disconnect()
If IsConnect = False Then Exit Sub
Conn.Close
Set Conn = Nothing
IsConnect = False
End Sub
以上几个是写的查询,与执行语句模块,一直用的很顺当
问题是现在有大量的循环查询,将这些查询函数嵌套在里面效率比较慢,我怀疑是不是Connect函数与Disconnect函数反复使用降低了效率,反复的链接断开耗费了大量时间,请老大们指点下,谢谢
[解决办法]
在模块里定义全局的数据库连接,记录集,表连接,查询
在main的时候就可以加载和连接了.
在最后程序退出的时候全体断开释放就可以了.
随用随连一般B/S才这么干. C/S就长连接吧