The connection cannot be used to perform this operation.
It is either closed or invalid in this context.
大家快来告诉我,这是什么错误?为什么会产生这种错误?如何解决?
快告诉我,否则我今天加班入要到深夜了!大慈大悲的师哥师姐,请快回答!
It is either closed or invalid in this context.
大家快来告诉我,这是什么错误?为什么会产生这种错误?如何解决?
快告诉我,否则我今天加班入要到深夜了!大慈大悲的师哥师姐,请快回答!
Dim rs As New ADODB.Recordset
Dim rst As New ADODB.Recordset
Dim str1 As String
Dim str2 As String
On Error GoTo errorhandler
rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open "ChuciKaijiDatabase", C_cnn, , , adCmdTable
If rst.RecordCount > 0 Then
rst.MoveFirst
If rst!初次开机 = True Then
rst!初次开机 = False
str1 = App.Path + "\SunBowTest_Database.mdb"
rst.Update
Else
rs.CursorType = adOpenStatic
rs.Open "DatabasemlDatabase", C_cnn, , , adCmdTable
If rs.RecordCount > 0 Then
rs.MoveFirst
If IsNull(rs!数据库目录) Then
str1 = App.Path + "\SunBowTest_Database.mdb"
Else
str1 = rs!数据库目录
End If
Else
MsgBox "数据库路径错误!"
str1 = App.Path + "\SunBowTest_Database.mdb"
rs.Close
End If
rs.Close
str2 = Right(str1, 23)
If str2 <> "SunBowTest_Database.mdb" Then
str1 = App.Path + "\SunBowTest_Database.mdb"
End If
End If
Else
str1 = App.Path + "\SunBowTest_Database.mdb"
End If
rst.Close
P_cnn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=cghotel;Data Source=lry"
P_cnn.Mode = adModeUnknown
P_cnn.Open
Exit Sub
errorhandler:
P_cnn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=cghotel;Data Source=lry"
P_cnn.Open
Exit Sub
我没有关闭连接啊!
在连接就可以!
P_cnn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=cghotel;Data Source=lry"
P_cnn.Open