Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Bad variable type (0x80020008) SQL Server sp_OAMethod

Avatar of carv99
carv99 asked on
DatabasesDelphiMicrosoft SQL Server 2005
6 Comments1 Solution1454 ViewsLast Modified:
Windows 7 64bit
MS SQL Server 64bit
Delphi 2007

I am trying to pass a string value (lpstr) to a com object I created and I am getting the that Bad Variable error when I run the following code:

  DECLARE @DeductionAmount money
  DECLARE @HResult int
  DECLARE @DLLObject int
  DECLARE @ErrorSource varchar (255)
  DECLARE @ErrorDesc varchar (255)
  EXEC @HResult = sp_OACreate 'TaxLibrary.CalculateTax', @DLLObject OUT
     
  EXEC @HResult = sp_OAMethod @DLLObject, 'CalculateTax', @DeductionAmount OUT, 1, '00-000-0000'
  IF @HResult <> 0
  BEGIN
    EXEC sp_OAGetErrorInfo @DLLObject, @ErrorSource OUT, @ErrorDesc OUT  
    RAISERROR('COM Error 0x%x, %s, %s', 16, 1, @HResult, @ErrorSource, @ErrorDesc)
    RETURN
  END


The definition for that error message is the following:
Bad variable type (0x80020008)
Data type of a Transact-SQL value passed as a method parameter did not match the Microsoft Visual Basic data type of the method parameter, or a NULL value was passed as a method parameter.
 
I did not use VB to create my com object, but I do not think that matters.  I have the parameter defined as of type lpstr in my com object.  I am not sure how I am to format the SQL any differently.

Thanks,