weixin_43930678
宇霸霸
采纳率0%
2019-10-12 17:27 阅读 786

VB6.0连接SQL Server2008 实时错误3709 请求的操作需要OLE DB会话对象,而当前的提供的程序不支持此对象

图片说明
图片说明

Public SqlConn As New ADODB.Connection
Public SqlRs As New ADODB.Recordset
Public SqlCmd As New ADODB.Command
Public Function DBConnect(strtype As String) As Boolean
Dim ConnStr As String
If SqlConn.State <> adSrareOpen Then
If strtype = "U" Then
SqlConn.Open ("FILE Name = " & App.Path & "\dbconn.udl")
Else
ConnStr = "Provider = SQLOLLEDB.1;Data Source = LAPTOP-ND06FMEL;User ID = sa;" & "Password = 12345678;Initial Catalog = StudentDB"
     SqlConn.Open (ConnStr)
End If
End If
  SqlCmd.ActiveConnection = SqlConn
DBConnect = True
End Function
Public Function ExecSQL(ByVal sql As String) As ADODB.Recordset
If SqlConn.State <> adStateOpen Then
DBConnect ("U")
End If
SqlCmd.CommandText = sql
Set ExecSQL = SqlCmd.Execute
End Function

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • caozhy 从今以后生命中的每一秒都属于我爱的人 2019-10-12 17:42

    看下你前面SqlConn那两个条件不满足的情况下,是不是根本没有Open

    点赞 1 评论 复制链接分享

相关推荐