vb6.0与SQL连接时出现这种提示,是什么原因,谢谢
我用VB与SQL写了一个程序,可一运行就提示“实时错误3709,连接无法执行此操作”我的程序是这样写的大家帮忙看看是什么原因,谢谢
'定义一个属性过程反映连接字符串
Public Property Get conString() As Variant
conString = "data source=.;initial catalog=Sims_four;user id=sa;password=;"
End Property
'定义一个提供者反映数据库类型
Public Property Get conProvide() As Variant
conProvide = "sqloledb"
End Property
Option Explicit
Private cnSIMS As ADODB.Connection '声明一个连接
Private rsSims As ADODB.Recordset '声明一个连接记录集
Public rs1 As ADODB.Recordset '声明一个连接到所需表的记录集
Public rs2 As ADODB.Recordset
Public rst As ADODB.Recordset
Private Data As Object
'---------------------------------------------------------
' 在类初始化时建立连接
'---------------------------------------------------------
Private Sub Class_Initialize()
On Error GoTo DbnotOpen
Set cnSIMS = New ADODB.Connection
With cnSIMS
.Provider = conProvide
.ConnectionString = conString
.ConnectionTimeout = 10
.Open
Set rst = New ADODB.Recordset
End With
Exit Sub
DbnotOpen:
If Err = -2147467259 Then
Set cnSIMS = Nothing
MsgBox "连接后台数据库失败!" & vbCrLf & vbCrLf & "请检查配置是否完好,数据库Sims_four是否存在?", vbOKOnly + vbInformation, "学生信息管理系统"
End
End If
End Sub
'---------------------------------------------------------
'data是一个指向ADO记录集的对象的引用
'用于设置class的数据源内容
'---------------------------------------------------------
Private Sub Class_GetDataMember(DataMember As String, Data As Object)
Set Data = rsSims
End Sub
'-------------------------------------------------------
'建立一个可以打开记录集的函数,需要是必须把表名传给函数
'-------------------------------------------------------
Public Function rsDK(Table As String)
Set rsSims = New ADODB.Recordset
With rsSims
.Source = Table
.ActiveConnection = cnSIMS
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open , , , , adCmdTable
End With
End Function
'-------------------------------------------------------
'建立一个可以打开记录集(动态游标)的函数
'需要把SQL语句传递给函数
'-------------------------------------------------------
Public Function rsDK1(sql As String)
Set rs1 = New ADODB.Recordset
With rs1
.Source = sql
.ActiveConnection = cnSIMS 每次一运行到这里就出错
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open , , , , adCmdText
End With
End Function
'-------------------------------------------------------
'建立一个可以打开记录集(静态游标)的函数
'需要把SQL语句传递给函数
'-------------------------------------------------------
Public Function rsDK2(sql As String)
Set rs2 = New ADODB.Recordset
With rs2
.Source = sql
.ActiveConnection = cnSIMS
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open , , , , adCmdText
End With
End Function
'-------------------------------------------------------
'类终止时,释放一切可能占据的资源
'-------------------------------------------------------
Private Sub Class_Terminate()
Set cnSIMS = Nothing
Set rs1 = Nothing
Set rs2 = Nothing
Set rsSims = Nothing
Set rst = Nothing
End Sub
--------------------编程问答--------------------
set .activeconnection = cnSIMS--------------------编程问答-------------------- 谢谢,
set .activeconnection = cnSIMS
我这样改了,还是原来的问题,是什么原因 --------------------编程问答-------------------- 是不是数据库连接的驱动程序没有写正确? --------------------编程问答-------------------- 楼上的,能不能说的详细一点,谢谢 --------------------编程问答-------------------- Private cnSIMS As ADODB.Connection
是不是把这换成
Dim cnSIMS As ADODB.Connection
--------------------编程问答-------------------- 楼主写代码喜欢脱了裤子放易做图。
补充:VB , 数据库(包含打印,安装,报表)