BUG: Sp_OA Procedures May Produce "Bad Variable Type" Error

Last reviewed: September 15, 1997
Article ID: Q173848
The information in this article applies to:
  • Microsoft SQL Server, version 6.5
BUG #: 17172 (Windows: 6.5)

SYMPTOMS

When you attempt to call sp_OAMethod, you may receive either of the following errors:

   Error: 0x800200008   Bad variable type
   Error: 0x80020005    Type mismatch

Either of these messages can be returned if your variable has not been initialized or contains a value of NULL.

If the datatype you are passing is not a string datatype, it cannot be passed by reference. Attempting to pass values other than string by reference results in the "Type mismatch" error.

WORKAROUND

To work around this problem, do any one of the following:

  • Initialize your variable to a default value.
  • Do not use NULL values.
  • Use string data types wherever possible.

STATUS

Microsoft has confirmed this to be a problem in SQL Server version 6.5. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The following script produces the "Bad Variable Type" error.

   DECLARE @object     int
   DECLARE @oResultSet int
   DECLARE @hr         int
   DECLARE @strInfo    char(255)
   EXEC @hr = sp_OACreate 'SQLOLE.SQLServer', @object OUT
   EXEC sp_OAGetErrorInfo @object


   EXEC sp_OAMethod @object,"Connect", NULL, ".", "sa"
   EXEC sp_OAGetErrorInfo @object

   EXEC sp_OAMethod @object,
         "ExecuteWithResultsAndMessages",
         @oResultSet OUT,
         @Messages=@strInfo OUT,
         @Command="print 'Hello'"

   EXEC sp_OAGetErrorInfo @object

If you initialize the @strInfo to "", the problem is avoided.

The following is a simple Visual Basic object method. It attempts to accept the integer value ByRef.

   Public Function DoIt(ByRef ID As Integer) As Integer
      DoIt = 1
      ID = 109
      End Function

The following script attempts to invoke the method but ends with the "Type mismatch" error.

   DECLARE @object    int
   DECLARE @hr        int

   DECLARE @iVal      int
   select @iVal = 1

   EXEC @hr = sp_OACreate MyTest.Class1', @object OUT
   EXEC sp_OAGetErrorInfo @object

   EXEC sp_OAMethod @object, "DoIt", NULL, @iVal OUTPUT
   EXEC sp_OAGetErrorInfo @object
   go


Additional query words: data type VB
Keywords : kbbug6.50 SSrvProg kbcode
Version : WINDOWS:6.5
Platform : WINDOWS
Issue type : kbbug
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 15, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.