BUG: Sp_OA Procedures May Produce "Bad Variable Type" ErrorLast reviewed: September 15, 1997Article ID: Q173848 |
The information in this article applies to:
SYMPTOMSWhen you attempt to call sp_OAMethod, you may receive either of the following errors:
Error: 0x800200008 Bad variable type Error: 0x80020005 Type mismatchEither 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.
WORKAROUNDTo work around this problem, do any one of the following:
STATUSMicrosoft 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 INFORMATIONThe 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 @objectIf 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 FunctionThe 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |