Calling COM component in SQL Server 2005 !!
Posted on 2007-11-24
I have created a class library in VB.NET 2005 - (Project name is - MySample):
Public Interface ISample
Function getSum(ByVal a As Integer, ByVal b As Integer) As Integer
Public Class CSample
Public Function getSum(ByVal a As Integer, ByVal b As Integer) As Integer Implements ISample.getSum
Return a + b
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:
-- 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
I have got NULL as result (Expected result is : 30). Can you please FIX my code and let me know where i am missing ?