Link to home
Start Free TrialLog in
Avatar of kishore_peddi
kishore_peddi

asked on

Calling COM component in SQL Server 2005 !!

Hi,

I have created a class library in VB.NET 2005 - (Project name is - MySample):

ISample.vb
=========

Public Interface ISample
    Function getSum(ByVal a As Integer, ByVal b As Integer) As Integer
End Interface

CSample.vb
========

Public Class CSample
    Implements ISample
    Public Function getSum(ByVal a As Integer, ByVal b As Integer) As Integer Implements ISample.getSum
        Return a + b
    End Function
End Class

I have registered the assembly in GAC as well as I have used REGASM tool to register it as COM component.

In SQL Server 2005 I have used the following script to call the COM component:

USE Sample
GO

-- Declare the variables

DECLARE @executionResult int
DECLARE @result varchar(200)
DECLARE @hnd int

-- Execute the COM component

EXEC @executionResult = sp_OACreate 'MySample.CSample', @hnd OUTPUT
EXEC @executionResult = sp_OAMethod @hnd, 'getSum', @result OUTPUT, 10, 20
EXEC @executionResult = sp_OADestroy @hnd

-- Display the result

SELECT @result

I have got NULL as result (Expected result is : 30). Can you please FIX my code and let me know where i am missing ?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kishore_peddi
kishore_peddi

ASKER

Hi angelIII,

Yes...but i am working on COM components. So i want to execute a simple program and understand how it works with Visual Studio 2005 and SQL Server 2005. Any help is greatly appreciated !

Thanks
so, did you try the correction of the variable declaration?
Yes...No luck.

Thanks