VB一直连接不上数据库 一直说对象关闭时不允许操作.. 纯新手 求大神们 指导
'/*connect*/PublicFunctionCreateConnectSqlForAll(ByRefpcnnAdoAsADODB.Connection,_ByVa...
'/*connect*/
Public Function CreateConnectSqlForAll(ByRef pcnnAdo As ADODB.Connection, _
ByVal pstrSqlServerName As String, _
Optional ByVal pstrSqlData As String, _
Optional ByRef pstrUserID As String, _
Optional ByRef pstrPassWord As String, _
Optional ByRef pstrConnectstring As String, Optional ByVal pstrdefault As String) As String
Dim cnnSqlServer As String
Const cntUserID = "sa" 'LYSXM
Const cntPwd = "123" 'lys2008SQLbest
On Error GoTo Errlbl
If pstrdefault = "lysxm2010" Or pstrdefault = "returnstring" Then
pstrUserID = cntUserID
pstrPassWord = cntPwd
End If
cnnSqlServer = "Driver={SQL Server}" & _
";Server=" & pstrSqlServerName & _
";Uid=" & pstrUserID & _
";Pwd=" & pstrPassWord & _
";Database=" & pstrSqlData
If pstrdefault = "returnstring" Then
pstrConnectstring = cnnSqlServer
Exit Function
End If
Set pcnnAdo = New ADODB.Connection
With pcnnAdo
.ConnectionTimeout = 1000 '60
.CommandTimeout = 0
.ConnectionString = cnnSqlServer
.CursorLocation = adUseClient adUseServer
.Mode = adModeReadWrite
.IsolationLevel = adXactCursorStability
.Open
End With
Exit Function
Errlbl:
Set pcnnAdo = Nothing
End Function 展开
Public Function CreateConnectSqlForAll(ByRef pcnnAdo As ADODB.Connection, _
ByVal pstrSqlServerName As String, _
Optional ByVal pstrSqlData As String, _
Optional ByRef pstrUserID As String, _
Optional ByRef pstrPassWord As String, _
Optional ByRef pstrConnectstring As String, Optional ByVal pstrdefault As String) As String
Dim cnnSqlServer As String
Const cntUserID = "sa" 'LYSXM
Const cntPwd = "123" 'lys2008SQLbest
On Error GoTo Errlbl
If pstrdefault = "lysxm2010" Or pstrdefault = "returnstring" Then
pstrUserID = cntUserID
pstrPassWord = cntPwd
End If
cnnSqlServer = "Driver={SQL Server}" & _
";Server=" & pstrSqlServerName & _
";Uid=" & pstrUserID & _
";Pwd=" & pstrPassWord & _
";Database=" & pstrSqlData
If pstrdefault = "returnstring" Then
pstrConnectstring = cnnSqlServer
Exit Function
End If
Set pcnnAdo = New ADODB.Connection
With pcnnAdo
.ConnectionTimeout = 1000 '60
.CommandTimeout = 0
.ConnectionString = cnnSqlServer
.CursorLocation = adUseClient adUseServer
.Mode = adModeReadWrite
.IsolationLevel = adXactCursorStability
.Open
End With
Exit Function
Errlbl:
Set pcnnAdo = Nothing
End Function 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询