-- SQL Server Stored Procedures call COM components
/* -- The following part is completed in VB. First, use VB as the simplest Component Project name: testsqlcom.
Class Name: testmath' function, which calculates the result of adding two integers
Public Function addme (A as long, B As long) as long
Addme = a + B
After the end function is compiled and generated, we can call this COM component in SQL Server.
-- * // * -- The following is the preceding DLL call in SQL -- */-- defines the variables used.
Declare @ err int, @ SRC varchar (255), @ DESC varchar (255)
Declare @ OBJ int, @ Re int -- create a call instance
Exec @ err = sp_oacreate 'testsqlcom. testmath', @ OBJ out
If @ err <> 0 goto lberr -- if creation fails, handle the error -- call the function in DLL
Exec @ err = sp_oamethod @ OBJ, 'addme ', @ Re out, 100,200
If @ err <> 0 goto lberr -- if a call error occurs, print the error processing. The returned result is: '+ STR (@ Re) -- release after completion.
Exec sp_oadestroy @ OBJ return lberr:
Exec sp_oageterrorinfo 0, @ SRC out, @ DESC out
Select cast (@ err as varbinary (4) as error code
, @ SRC as error source, @ DESC as error description