SQL Server Stored Procedures call COM components

Source: Internet
Author: User
-- 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.