Public Function ufmRecordSet(ByVal bstrSQL As String) As Recordset
Dim pcnnCn As New ADODB.Connection
Dim precRS As New ADODB.Recordset
If mstrConnect = "" Then
MsgBox "连接字符串为空", vbOKOnly + 64, ""
Exit Function
End If
If bstrSQL = "" Then
MsgBox "SQL语句为空", vbOKOnly + 64, ""
Exit Function
End If
pcnnCn.ConnectionTimeout = mintTimeout
pcnnCn.CommandTimeout = mintTimeout
pcnnCn.Open mstrConnect
precRS.CursorLocation = adUseClient
precRS.LockType = adLockOptimistic
precRS.CursorType = adOpenStatic
Set precRS.ActiveConnection = pcnnCn
precRS.Open bstrSQL
Set precRS.ActiveConnection = Nothing
Set ufmRecordSet = precRS
Set precRS = Nothing
Set pcnnCn = Nothing
End Function
mstrConnect = "Provider=SQLOLEDB.1;Password=" & mstrSQLPassword & ";Persist Security " & _
" Info=True;User ID=" & mstrSQLUser & ";Initial Catalog=" & mstrSQLDBName & _
";Data Source=" & mstrSQLServerName
Public Const mintTimeout = 800 '数据连接延时