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