SQL Server implements data change triggering information

Source: Internet
Author: User

1, the establishment of stored procedures, the function is to dynamically write information in the file, can be called in a trigger or stored procedure.

SETAnsi_nulls onGOSETQuoted_identifier onGOCreateproc [dbo].[Sp_sendmagtofile](  @path varchar( -),  @fileName varchar( -),   @msg varchar( $)) asbegin  DECLARE   @object   int  DECLARE   @hr   int  DECLARE   @src   varchar(255),@desc   varchar(255)  Declare   @tmp   int  Declare   @strPath     nvarchar( +)  Set   @strPath=@path+'\'+@fileName       --Group as file name  EXEC   @hr   =sp_OACreate'Scripting.FileSystemObject',@object outIF   @hr   <>   0  BEGIN        EXECsp_OAGetErrorInfo@object,@srcOut,@desc outSELECThr=Convert(varbinary(4),@hr), Source=@src, Description=@desc        RETURN  END   --Creating Documents  EXEC   @hr   =sp_OAMethod@object,'CreateTextFile',@tmpOUTPUT,@strPath  IF   @hr   <>   0  BEGIN        EXECsp_OAGetErrorInfo@object          RETURN  END  --write the @msg into the file.  EXEC   @hr   =sp_OAMethod@tmp,'Write',NULL,@msg  IF   @hr   <>   0  BEGIN        EXECsp_OAGetErrorInfo@object          RETURN  END  --Close file  EXEC   @hr   =sp_OAMethod@tmp,'Close',NULL  IF   @hr   <>   0  BEGIN    EXECsp_OAGetErrorInfo@object    RETURN  ENDEnd

2, the server to listen to the folder is updated, if the update to send information or execute programs and so on.

3, this can reduce the pressure of network transmission.

4, can also carry out HTTP, to achieve the function of updating data

sp_configure'Show advanced Options',1;GORECONFIGURE;GOsp_configure'Ole Automation Procedures',1;GORECONFIGURE;GOEXECsp_configure'Ole Automation Procedures';GO/*parameter description? @URL =http Request address @status= status generation? @returnText = return? @object = Object Token @errsrc= error source codec?*/CREATE PROCEDUREP_get_httprequestdata (@URL varchar( -),    @status int=0Out ,@returnText varchar( -)="'Out ) asBEGIN    DECLARE @object int,    @errSrc int    /*Initialize the*/    EXEC @status =sp_OACreate'msxml2.serverxmlhttp.3.0',@object outIF @status <> 0    BEGIN     EXECsp_OAGetErrorInfo@object,@errSrcOut,@returnText outRETURN    END    /*Create a link*/    EXEC @status=sp_OAMethod@object,'Open',NULL,'GET',@URL    IF @status <> 0    BEGIN     EXECsp_OAGetErrorInfo@object,@errSrcOut,@returnText outRETURN    END    EXEC @status=sp_OAMethod@object,'setRequestHeader','Content-type','application/x-www-form-urlencoded'    /*initiating a request*/    EXEC @status=sp_OAMethod@object,'Send',NULL     IF @status <> 0     BEGIN      EXECsp_OAGetErrorInfo@object,@errSrcOut,@returnText outRETURN    END         /*Gets the return*/    EXEC @status=sp_OAGetProperty@object,'ResponseText',@returnText outIF @status <> 0     BEGIN      EXECsp_OAGetErrorInfo@object,@errSrcOut,@returnText outRETURN    ENDEND;

SQL Server implements data change triggering information

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.