Solved

Calling COM component in SQL Server 2005 !!

Posted on 2007-11-24
4
201 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

11 Experts available now in Live!

Get 1:1 Help Now