Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 752449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:46:58+00:00 2026-05-14T14:46:58+00:00

I’m getting an inexplicable error with an ADO command in VB6 run against a

  • 0

I’m getting an inexplicable error with an ADO command in VB6 run against a SQL Server 2005 database.

Here’s some code to demonstrate the problem:

Sub ADOCommand()
   Dim Conn As ADODB.Connection
   Dim Rs As ADODB.Recordset
   Dim Cmd As ADODB.Command

   Dim ErrorAlertID As Long
   Dim ErrorTime As Date

   Set Conn = New ADODB.Connection
   Conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=database;Data Source=server"
   Conn.CursorLocation = adUseClient
   Conn.Open

   Set Rs = New ADODB.Recordset
   Rs.CursorType = adOpenStatic
   Rs.LockType = adLockReadOnly

   Set Cmd = New ADODB.Command
   With Cmd
      .Prepared = False
      .CommandText = "ErrorAlertCollect"
      .CommandType = adCmdStoredProc
      .NamedParameters = True
      .Parameters.Append .CreateParameter("@ErrorAlertID", adInteger, adParamOutput)
      .Parameters.Append .CreateParameter("@CreateTime", adDate, adParamOutput)
      Set .ActiveConnection = Conn
      Rs.Open Cmd

      ErrorAlertID = .Parameters("@ErrorAlertID").Value
      ErrorTime = .Parameters("@CreateTime").Value
   End With
   Debug.Print Rs.State ''// Shows 0 - Closed
   Debug.Print Rs.RecordCount ''// Of course this fails since the recordset is closed
End Sub

So this code was working not too long ago but now it’s failing on the last line with the error:

Run-time error '3704': Operation is not allowed when the object is closed

Why is it closed? I just opened it and the SP returns rows.

I ran a trace and this is what the ADO library is actually submitting to the server:

declare @p1 int
set @p1=1
declare @p2 datetime
set @p2=''2010-04-22 15:31:07:770''
exec ErrorAlertCollect @ErrorAlertID=@p1 output,@CreateTime=@p2 output
select @p1, @p2

Running this as a separate batch from my query editor yields:

Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '2010'.

Of course there’s an error. Look at the double single quotes in there. What the heck could be causing that? I tried using adDBDate and adDBTime as data types for the date parameter, and they give the same results.

When I make the parameters adParamInputOutput, then I get this:

declare @p1 int
set @p1=default
declare @p2 datetime
set @p2=default
exec ErrorAlertCollect @ErrorAlertID=@p1 output,@CreateTime=@p2 output
select @p1, @p2

Running that as a separate batch yields:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'default'.
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'default'.

What the heck? SQL Server doesn’t support this kind of syntax. You can only use the DEFAULT keyword in the actual SP execution statement.

I should note that removing the extra single quotes from the above statement makes the SP run fine.

… Oh my. I just figured it out. I guess it’s worth posting anyway.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:46:58+00:00Added an answer on May 14, 2026 at 2:46 pm

    The answer is that the stored procedure needed SET NOCOUNT ON at the top, since ADO stops the moment it gets a “Rows Affected” response back, and the stored procedure has an update statement before the final select.

    I have no clue why the trace is showing syntax from ADODB that doesn’t run correctly when submitted on its own, but clearly the ADODB library was NOT getting an error with its queries. The whole problem was SET NOCOUNT ON missing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 365k
  • Answers 365k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use the data in the /proc filesystem to… May 14, 2026 at 3:57 pm
  • Editorial Team
    Editorial Team added an answer Do you still get the error when you use a… May 14, 2026 at 3:57 pm
  • Editorial Team
    Editorial Team added an answer You can use array_chunk to create a single array comprised… May 14, 2026 at 3:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.