Call COM components during the stored procedure of SQL Server
Keywords: SQL Server
Call COM components during SQL Server / ** *** Tofu production is a boutique http://www.asp888.net tofu technology station, please indicate the function of the T-SQL language of the * / SQL Server It is very powerful, but there is always some limitations and inconvenience, one day, tofu wants why it is not like ASP a lot of borrowing components? If you don't have to do it, I will start to find a SQL online book, huh, I finally found a SQL system stored procedure sp_oacreate, let's take a look at the magic of this stored procedure together, first we first use VB first. As a simplest component, this component is very simple. This component is very simple. In the specific work, you can write a multi-component Project Name: Testsqlcomclass name: Testmathpublic Function AddME ( A as long, b askON AS Long Addme = a Bend Function After compiling, we can call the COM component in SQL Server to call Declare @i intDeclare @intret INTDDECLARE @intretcode intDeclare @strerr varchar (255) Declare @ strerr1 varchar (255) / * First create a COM instance * / exec @ret_code = sp_oacreate "testsqlcom.testmath", @i outif@intretcode <> 0begin / * creation instance failed * / exec sp_oageterrorinfo @i, @strerr out, @ STRERR1 OUT Print "Create an instance failed, the reason for failure is:" @strerr "" @ strerr1 return / * created success, start call * / exec @ItRetcode = sp_oamethod @ i, 'addme', @ Ret Out 100, 200IF @intretcode <> 0begin / * call method error * / exec sp_oageterrorinfo @i, @strerr out, @ strerr1 outprint "The reason failed, the reason for failure is ::" @strer "" @ strerr1 EXEC SP_OADESTROY @i returnendprint "The result is" Str (@intret) exec sp_oadestroy @i before the stored procedure output STEP 4: The result is 300 I In this article, we introduced the method of using components in SQL Server. For details, please see SQL ONLONE BOOK