Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calling COM component in SQL Server 2005 !!

Posted on 2007-11-24
4
Medium Priority
?
210 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 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 143

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

783 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