Friday, February 10, 2012

Calling VB dll method: sp_OAMethod Error

I have VB dll with a few methods that I need to access from my database.
Here's the code w/in sql server:
DECLARE @.retVal INT
DECLARE @.comHandle INT
DECLARE @.errorSource VARCHAR(8000)
DECLARE @.errorDescription VARCHAR(8000)
DECLARE @.retString VARCHAR(180)
--
--INSTATIATE OBJECT--
--
EXEC @.retVal = sp_OACreate 'DB_Encryption.Convert_String', @.comHandle OUTPUT
IF (@.retVal <> 0)
BEGIN
-- Trap errors if any
EXEC sp_OAGetErrorInfo @.comHandle, @.errorSource OUTPUT, @.errorDescription
OUTPUT
SELECT [Error Source] = @.errorSource, [Description] = @.errorDescription
RETURN
END
--CALL METHOD--
--
EXEC @.retVal = sp_OAMethod @.comHandle, 'Create_newStr', @.retString OUTPUT,
@.param='254616'
IF (@.retVal <> 0)
BEGIN
-- Trap errors if any
EXEC sp_OAGetErrorInfo @.comHandle, @.errorSource OUTPUT, @.errorDescription
OUTPUT
SELECT [Error Source] = @.errorSource, [Description] = @.errorDescription
RETURN
END
SELECT @.retString
EXEC sp_OADestroy @.comHandle
I know the object is being instantiated because no errors are returned if I
only exec that piece. However, when I try to call my method, I received the
following error:
Error Source:
ODSOLE Extended Procedure
Description:
Unknown name.
I've verified the method's name (and tried calling other ones).Couple of thoughts:
Did you test your DLL from VBScript using late binding?
Did you check if the value of comHandle non zero or non NULL?
What is the function prototype of the VB function you are calling? Some
constructs are not supported, you are limited IDispatch (COM Automation) at
best and have to substract the SQL XP limitation on top of that, since not
all objects are supported, for example types as Object and Variant are not
understood.
Is your object STA or MTA?
GertD@.SQLDev.Net
"Eric" <Eric@.discussions.microsoft.com> wrote in message
news:4D97C5FB-4976-487B-9D39-98E261C4BCFA@.microsoft.com...
>I have VB dll with a few methods that I need to access from my database.
> Here's the code w/in sql server:
> DECLARE @.retVal INT
> DECLARE @.comHandle INT
> DECLARE @.errorSource VARCHAR(8000)
> DECLARE @.errorDescription VARCHAR(8000)
> DECLARE @.retString VARCHAR(180)
> --
> --INSTATIATE OBJECT--
> --
> EXEC @.retVal = sp_OACreate 'DB_Encryption.Convert_String', @.comHandle
> OUTPUT
> IF (@.retVal <> 0)
> BEGIN
> -- Trap errors if any
> EXEC sp_OAGetErrorInfo @.comHandle, @.errorSource OUTPUT, @.errorDescription
> OUTPUT
> SELECT [Error Source] = @.errorSource, [Description] = @.errorDescription
> RETURN
> END
> --
> --CALL METHOD--
> --
> EXEC @.retVal = sp_OAMethod @.comHandle, 'Create_newStr', @.retString OUTPUT,
> @.param='254616'
> IF (@.retVal <> 0)
> BEGIN
> -- Trap errors if any
> EXEC sp_OAGetErrorInfo @.comHandle, @.errorSource OUTPUT, @.errorDescription
> OUTPUT
> SELECT [Error Source] = @.errorSource, [Description] = @.errorDescription
> RETURN
> END
> SELECT @.retString
> EXEC sp_OADestroy @.comHandle
> I know the object is being instantiated because no errors are returned if
> I
> only exec that piece. However, when I try to call my method, I received
> the
> following error:
> Error Source:
> ODSOLE Extended Procedure
> Description:
> Unknown name.
> I've verified the method's name (and tried calling other ones).
>|||I'm already using late binding (set obj = CreatObject) and it works when
called from an ASP page.
The value of column handle is not null. I have no idea what you are
referring to in the next point (function prototype).
The threading model is set to Apartment Threaded.
"Gert E.R. Drapers" wrote:

> Couple of thoughts:
> Did you test your DLL from VBScript using late binding?
> Did you check if the value of comHandle non zero or non NULL?
> What is the function prototype of the VB function you are calling? Some
> constructs are not supported, you are limited IDispatch (COM Automation) a
t
> best and have to substract the SQL XP limitation on top of that, since not
> all objects are supported, for example types as Object and Variant are not
> understood.
> Is your object STA or MTA?
> GertD@.SQLDev.Net
> "Eric" <Eric@.discussions.microsoft.com> wrote in message
> news:4D97C5FB-4976-487B-9D39-98E261C4BCFA@.microsoft.com...
>
>

No comments:

Post a Comment