Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL2K, Excel VBA using ADO:  When command.ActiveConnection = gcn, it always contains a parameter with it.  How to find and remove?

Posted on 2007-11-28
5
Medium Priority
?
657 Views
Last Modified: 2012-06-21
In Excel VBA I am using ADO to connect to a SQL2K db, and set a recordset object = SP with one parameter

The SP works fine in QA

cmdPLCY.CommandType = adCmdStoredProc
cmdPLCY.CommandText = "spm_POLICY_INFO"
cmdPLCY.ActiveConnection = gcnCASES    '<-- Looky Here

After execution of the third line above, when I eyeball the Locals window in cmdPLCY.Parameters, it contains one prarameter of @RETURN_VALUE.  I use this in SP's alot, but I did not set it anywhere in VBA code, and have no idea how it could be attaching itself to my connection object.

The sub that sets my connection object (below), is working fine:

Public Function scnCASES() As Boolean

'some stuff omitted

Dim sConnect As String
sConnect = "PROVIDER=SERVER;Driver=SQLServer;Server=SERVER_NAME;UID=USER_NAME;PWD=PASSWORD;Database=DB_NAME;"

If gcnCASES Is Nothing Then
    Set gcnCASES = CreateObject("ADODB.Connection")
    gcnCASES.ConnectionString = sConnect
    gcnCASES.Open
End If

If gcnCASES.State <> adStateClosed Then
    scnCASES = True
Else
    scnCASES = False
End If
   
End Function

TIA
Jim
0
Comment
Question by:Jim Horn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 33

Expert Comment

by:Jeroen Rosink
ID: 20368594
Didn't you made a typo?
you try to set the connection using gcnCASES

though the function is called: scnCASES

or should you use:

cmdPLCY.ActiveConnection = gcnCASES(scnCASES)
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 400 total points
ID: 20368601
>, and have no idea how it could be attaching itself to my connection object.
you mean, the command object :)

now, indeed, a stored procedure in SQL Server does RETURN a value implicitely, and ADO takes that into account, assigning such a parameter implicitly.

0
 
LVL 66

Author Comment

by:Jim Horn
ID: 20368634
>Didn't you made a typo?
Nope.

'Global variable
Dim gcnCases as adodb.connection

'In every sub/function
If gcnCases Is Nothing then call scnCASES   'which sets the gcnCases global variable.

>and have no idea how it could be attaching itself to my connection object.
>you mean, the command object.
Correct, the command object.  My typo.

The SP in question returns a SELECT * FROM #tmp, with 30ish columns.
It also uses a bunch of variables, but @RETURN_VALUE is not one of them, and nowhere before the final SELECT * FROM #tmp is there a SELECT @anything.
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 1600 total points
ID: 20372398
Further to Angel's comment, here is an MSKB article that mentions this: http://support.microsoft.com/kb/285295
Regards,
Rory
0
 
LVL 66

Author Comment

by:Jim Horn
ID: 20373974
Okay, that makes sense.

I discovered that after I had SET NOCOUNT ON in all the SP's they worked, regardless of the fact that my command objects had a parameter of @RETURN_VALUE.

Thanks guys.
Jim
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question