Solved

Calling COM component in SQL Server 2005 !!

Posted on 2007-11-24
4
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 143

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 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

634 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