简体   繁体   English

请求的操作需要一个OLE DB会话对象— VB6至SQL Server 2000

[英]Requested operation requires an OLE DB Session object — VB6 to SQL Server 2000

I'm attempting to get into a VB6 application that was written for a client about a decade back, but intermittently I keep getting this error. 我试图进入大约十年前为客户编写的VB6应用程序,但间歇性地我不断收到此错误。 The application has a login required upon launch, and upon entering the login provided for me (I am 100% certain it is correct), the following error is given: 该应用程序在启动时需要登录,并且在输入为我提供的登录名后(我100%确信它是正确的),将出现以下错误:

Run-time error '3709' 运行时错误'3709'
Requested operation requires an OLE DB Session object, which is not supported by the current provider. 请求的操作需要OLE DB会话对象,当前提供程序不支持该对象。

What's truly bizarre is that last night I was able to log in with absolutely no problems. 真正奇怪的是,昨晚我能够毫无问题地登录。 However, I had this problem before about a week back, but I was out of town for several days and when I cam back I could log in again. 但是,大约一周前,我遇到了这个问题,但是我出城几天了,当我回来时,我可以再次登录。 Before that initial instance, I was able to log in fine. 在该初始实例之前,我可以正常登录。 I noticed a similar question already posted, but the solution that was given did not work for me. 我注意到已经发布了一个类似的问题,但是给出的解决方案对我不起作用。 Here's the code pertaining to establishing the database connection. 这是与建立数据库连接有关的代码。 Note, the Serv1, Use1, PW1 etc are just fillers for server names/usernames/passwords. 注意,Serv1,Use1,PW1等只是服务器名称/用户名/密码的填充符。

Public Function GetConnected()

' This function decides which server to connect and makes the connection

'Determines which connection string to use
If frmSplash.Text1 = "1" Or frmSplash.Text1 = "apc" Then 'server location
'determines if the logon contains '1' or 'apc'
    'APC connection code
    strSQLServerName = "(Serv1)"
    strSQLDBUserName = "Use1"
    strSQLDBPassword = "PW1"
    strSQLPort = ""

ElseIf frmSplash.Text1 = "2" Then
    'Laptop connection string
    strSQLServerName = "(Serv1)"
    strSQLDBUserName = "Use2"
    strSQLDBPassword = "PW2"
    strSQLPort = ""
Else
    'Client connection code
    strSQLServerName = "Serv2
    strSQLDBUserName = "Use3"
    strSQLDBPassword = "PW3"
    strSQLPort = ""
End If 'server location


    'If (m_DBConnection Is Nothing) Then
    Set m_DBConnection = New ADODB.Connection
    'End If

    SessionLocation = frmSplash.LocationCombo.Text

'***************************************
'Connecs to database based on location
    If frmSplash.LocationCombo.Text = "Loc1" Then
    strSQLDBName = "ServLoc1"
    ElseIf frmSplash.LocationCombo.Text = "Loc2" Then
    strSQLDBName = "ServLoc2"
    Else
    strSQLDBName = "ServLoc3"
    End If
'**************************

'Builds connection string
    m_DBConnection.ConnectionString = "Provider=SQLOLEDB;" & _
    "Data Source = '" & strSQLServerName & strSQLPort & "';" & _
    "uid=" & strSQLDBUserName & ";" & _
    "pwd=" & strSQLDBPassword & ";" & _
    "Database=" & strSQLDBName & ";"  

On Error GoTo errorhandler
    m_DBConnection.Open
    If (m_DBConnection Is Nothing) Then
        MsgBox "Connection Failed"
    End If
Exit Function

errorhandler:
    MsgBox ("Problem with the Server")
    'MsgBox "Connection State " & GetState(m_DBConnection.State)
End Function

Public Function ExecuteSQL(strSQL As String) As ADODB.Recordset
    'Dim cmd As ADODB.Command

    Set cmd = New ADODB.Command

    **cmd.ActiveConnection = m_DBConnection** <-----(Error occurs here)
    cmd.CommandType = adCmdText
    cmd.CommandText = strSQL

    Set ExecuteSQL = cmd.Execute

Exit Function

Variable definitions: 变量定义:

Public strSQLServerName  'Holds the name of the SQL Server
Public strSQLDBUserName  'Holds the user name (for SQL Server Authentication)
Public strSQLDBPassword  'Holds the password (for SQL Server Authentication)
Public strSQLDBName      'Holds name of a database on the server
Public strSQLPort        'Holds the Port Number
Public SessionUser As Integer    ' To Track the type of User (3 Levels)
Public SessionLocation As String ' To Track the DB throughout the Session
Public m_DBConnection As ADODB.Connection
Public cmd As ADODB.Command

This is my first time working in VB6 and I'm a bit at a loss. 这是我第一次在VB6中工作,我有点茫然。 I can't figure out why it works sometimes and not others. 我不知道为什么有时会起作用,而其他人则无法。 If anyone has any insights, they'd be very much appreciated. 如果有人有任何见解,将不胜感激。

Change your error handling to get a better idea of what is going on. 更改错误处理以更好地了解发生了什么。 Since you are setting your conncection (Set m_DBConnection = New ADODB.Connection) to a new object, your check (m_DBConnection Is Nothing) doesn't do much since the ojbect is certain to already exist. 由于您要将连接(设置m_DBConnection = New ADODB.Connection)设置为新对象,因此检查(m_DBConnection Is Nothing)不会做太多事情,因为对象已确定已经存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 请求的操作需要OLE DB会话对象... - 通过ADO将Excel连接到SQL服务器 - Requested operation requires an OLE DB Session object… - Connecting Excel to SQL server via ADO SQL Server 2000,ADO 2.8,VB6 - SQL Server 2000, ADO 2.8, VB6 从 VB6 向表中插入数据:多步 OLE DB 操作生成错误 - Insert data to a table from VB6: Multiple-step OLE DB operation generated errors 请求的操作需要在SQL Server中进行提升(以管理员身份运行) - The requested operation requires elevation (Run as administrator) in SQL Server 无法执行请求的操作,因为链接服务器“SSAS”的 OLE DB 提供程序“MSOLAP”不支持所需的接口 - The requested operation could not be performed because OLE DB provider 'MSOLAP' for Linked server 'SSAS' does not support the required interface 使用VB6访问SQL Server - Accessing SQL Server with VB6 使用ole自动化在SQL Server 2000中发送CDO电子邮件时出错 - Error using ole automation to send CDO Email in SQL Server 2000 使用VB6中的ADO将大量数据从ms访问表(带有2.3 mimion记录)复制到sql 2000服务器 - Copy large amount of data from ms access table (with 2.3 mimion recs) to sql 2000 server using ADO in VB6 等于操作Sql Server 2000的集合冲突 - COLLATION Conflict For Equal To Operation Sql Server 2000 SQL Server 2000无效的浮点操作 - SQL Server 2000 invalid Floating Point Operation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM