Microsoft KB Archive/172239: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - "&" to "&")
 
(3 intermediate revisions by the same user not shown)
Line 53: Line 53:


The resolution to this problem is to call DoEvents function after opening the resultset. For example:
The resolution to this problem is to call DoEvents function after opening the resultset. For example:
<pre class="codesample">  Set rs = cn.OpenResultset(&quot;select * from Authors&quot;, _
<pre class="codesample">  Set rs = cn.OpenResultset("select * from Authors", _
       rdOpenKeyset, rdConcurValues)
       rdOpenKeyset, rdConcurValues)
   DoEvents
   DoEvents
                 </pre>
                 </pre>
If you use the OpenResultset method with the rdAsyncEnable option, you need to use the following code to workaround the problem:
If you use the OpenResultset method with the rdAsyncEnable option, you need to use the following code to workaround the problem:
<pre class="codesample">  Set rs = cn.OpenResultset(&quot;select * from Authors&quot;, _
<pre class="codesample">  Set rs = cn.OpenResultset("select * from Authors", _
       rdOpenKeyset, rdConcurValues, rdAsyncEnable)
       rdOpenKeyset, rdConcurValues, rdAsyncEnable)
   While rs.StillExecuting
   While rs.StillExecuting
Line 85: Line 85:
<li><p>Insert the following code into the General Declarations section of Class1 and replace ServerName with appropriate SQL server name.<br />
<li><p>Insert the following code into the General Declarations section of Class1 and replace ServerName with appropriate SQL server name.<br />
<br />
<br />
'''Note''' You must change UID =&lt;username&gt; and PWD =&lt;strong password&gt; to the correct values before you run this code. Make sure that UID has the appropriate permissions to perform this operation on the database.</p>
'''Note''' You must change UID =<username> and PWD =<strong password> to the correct values before you run this code. Make sure that UID has the appropriate permissions to perform this operation on the database.</p>
<pre class="codesample">      Private WithEvents cn As rdoConnection
<pre class="codesample">      Private WithEvents cn As rdoConnection


       Private Sub cn_QueryComplete(ByVal Query As RDO.rdoQuery, _
       Private Sub cn_QueryComplete(ByVal Query As RDO.rdoQuery, _
                                   ByVal ErrorOccurred As Boolean)
                                   ByVal ErrorOccurred As Boolean)
         MsgBox &quot;Query Done --&gt; From QueryComplete Event.&quot;
         MsgBox "Query Done --> From QueryComplete Event."
       End Sub
       End Sub


Line 97: Line 97:
         Set cn = New rdoConnection
         Set cn = New rdoConnection
         With cn
         With cn
           .Connect = &quot;UID=&lt;username&gt;;PWD=&lt;strong password&gt;;database=pubs;&quot; _
           .Connect = "UID=<username>;PWD=<strong password>;database=pubs;" _
               &amp; &quot;Server=ServerName;&quot; _
               & "Server=ServerName;" _
               &amp; &quot;driver={SQL Server};DSN='';&quot;
               & "driver={SQL Server};DSN='';"
           .QueryTimeout = 5
           .QueryTimeout = 5
           .CursorDriver = rdUseClientBatch
           .CursorDriver = rdUseClientBatch
Line 105: Line 105:
         End With
         End With
         Set rs = cn.OpenResultset( _
         Set rs = cn.OpenResultset( _
           &quot;select * from Authors&quot;, _
           "select * from Authors", _
           rdOpenKeyset, rdConcurValues)
           rdOpenKeyset, rdConcurValues)
         'DoEvents
         'DoEvents

Latest revision as of 12:30, 21 July 2020

Article ID: 172239

Article Last Modified on 11/7/2003



APPLIES TO

  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition



This article was previously published under Q172239

SYMPTOMS

Program code in the QueryComplete event procedure of a rdoConnection object will not execute if you use the OpenResultset method to execute a query in a class module.

RESOLUTION

The resolution to this problem is to call DoEvents function after opening the resultset. For example:

   Set rs = cn.OpenResultset("select * from Authors", _
       rdOpenKeyset, rdConcurValues)
   DoEvents
                

If you use the OpenResultset method with the rdAsyncEnable option, you need to use the following code to workaround the problem:

   Set rs = cn.OpenResultset("select * from Authors", _
       rdOpenKeyset, rdConcurValues, rdAsyncEnable)
   While rs.StillExecuting
       DoEvents
   Wend
   DoEvents
                

STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Standard EXE project in Visual Basic 5.0. Form1 is created by default.
  2. Add a new Class Module (Class1) to the project.
  3. Insert the following code into the General Declarations section of Class1 and replace ServerName with appropriate SQL server name.

    Note You must change UID =<username> and PWD = to the correct values before you run this code. Make sure that UID has the appropriate permissions to perform this operation on the database.

          Private WithEvents cn As rdoConnection
    
          Private Sub cn_QueryComplete(ByVal Query As RDO.rdoQuery, _
                                      ByVal ErrorOccurred As Boolean)
            MsgBox "Query Done --> From QueryComplete Event."
          End Sub
    
          Public Sub QueryCompleteTest()
            Dim rs As rdoResultset
            Set cn = New rdoConnection
            With cn
               .Connect = "UID=<username>;PWD=<strong password>;database=pubs;" _
                   & "Server=ServerName;" _
                   & "driver={SQL Server};DSN='';"
               .QueryTimeout = 5
               .CursorDriver = rdUseClientBatch
               .EstablishConnection rdDriverNoPrompt
            End With
            Set rs = cn.OpenResultset( _
               "select * from Authors", _
               rdOpenKeyset, rdConcurValues)
            'DoEvents
          End Sub
                            
  4. Add a CommandButton (Command1) to Form1.
  5. Insert the following code into the Click event of Command1:

          Private Sub Command1_Click()
            Dim ClsQuery As New Class1
            ClsQuery.QueryCompleteTest
          End Sub
                            
  6. Select Project\References, and check Microsoft Remote Data Object 2.0.
  7. Press the F5 key to run the program.
  8. Click on Command1. Note that the QueryComplete event is not triggered and no message box appears on screen.



Additional query words: kbVBp500 kbVBp600 kbdse kbDSupport kbVBp kbVBp400 kbRDO

Keywords: kbbug KB172239