Solved

Calling COM component in SQL Server 2005 !!

Posted on 2007-11-24
4
202 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:kishore_peddi
  • 2
  • 2
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 20344931
to start with, I would not declare the @result as varchar(200), but as int...
DECLARE @result int

now, I understand that this is an "exercice" to get sample things working, but are you aware of the CLR integration possibilities, ie to compile a .net code directly as procedure/function into sql server 2005?
0
 

Author Comment

by:kishore_peddi
ID: 20344949
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
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20345200
so, did you try the correction of the variable declaration?
0
 

Author Comment

by:kishore_peddi
ID: 20346566
Yes...No luck.

Thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now