Logo
English Russian German French Spanish Italian
contact usprivacy
   Support Forums
chart
• About the product
• Download
• Sample projects:
Using with Visual Basic
Using with VB.NET
Using with C#
Using with ASP
Using with ASP.NET
Using with Office (VBA)
Using with VBScript
Using with JavaScript
Using with SQL Server
• Support Forum
OISV - Organization of Independent Software Vendors - Contributing Member
Winsock Component - Using with SQL server

Sending e-mail, using OstroSoft Winsock Component (osWinsock.dll)
Download sample query

Minimum requirements: osWinsock.dll*
* If you don't have OstroSoft Winsock Component, see installation instructions

1. Open SQL Server Query Analyzer and enter the following code:

DECLARE @hTCP int
DECLARE @nConnectionResult int
DECLARE @nPort int
DECLARE @sServer varchar(255)
DECLARE @sPage varchar(255)
DECLARE @sSource varchar(8000)
-- replace with your parameters:
SET @sServer = 'www.ostrosoft.com'
SET @nPort = 80
-- has to be relatively small page,  
-- since buffer is only 8000 characters
SET @sPage = '/ostronet/help/html/ostr34c0.htm'

DECLARE @nRet int, @src varchar(255), @desc varchar(255)

-- create TCP object (blocking socket)
EXEC @nRet = sp_OACreate 'OSWINSCK.TCP', @hTCP OUT
IF @nRet <> 0
BEGIN
  EXEC sp_OAGetErrorInfo @hTCP, @src OUT, @desc OUT
  PRINT 'Error ' + CONVERT(varchar(4), @nRet)+ ': ' + @desc
  RETURN
END

-- connect to remote host
EXEC @nRet = sp_OAMethod @hTCP, 'Connect', 
  @nConnectionResult OUT, @sServer, @nPort
IF @nRet <> 0
BEGIN
  EXEC sp_OAGetErrorInfo @hTCP, @src OUT, @desc OUT
  PRINT 'Error ' + CONVERT(varchar(4), @nRet)+ ': ' + @desc
  RETURN
END

IF @nConnectionResult = 0 -- connected
BEGIN
  -- send HTTP request
  SET @sPage = 'GET ' + @sPage + ' HTTP/1.0' + 
    CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10)
  EXEC @nRet = sp_OAMethod @hTCP, 'SendData', NULL, @sPage
  IF @nRet <> 0
  BEGIN
    EXEC sp_OAGetErrorInfo @hTCP, @src OUT, @desc OUT
    PRINT 'Error ' + CONVERT(varchar(4), @nRet)+ ': ' + @desc
    RETURN
  END
  -- suspend execution to allow remote host to respond
  EXEC @nRet = sp_OAMethod @hTCP, 'Sleep', NULL, 1000
  IF @nRet <> 0
  BEGIN
    EXEC sp_OAGetErrorInfo @hTCP, @src OUT, @desc OUT
    PRINT 'Error ' + CONVERT(varchar(4), @nRet)+ ': ' + @desc
    RETURN
  END
  -- read response
  EXEC @nRet = sp_OAMethod @hTCP, 'GetData', @sSource OUT
  IF @nRet <> 0
  BEGIN
    EXEC sp_OAGetErrorInfo @hTCP, @src OUT, @desc OUT
    PRINT 'Error ' + CONVERT(varchar(4), @nRet)+ ': ' + @desc
    RETURN
  END
  -- read response
  EXEC @nRet = sp_OAMethod @hTCP, 'Disconnect'
  IF @nRet <> 0
  BEGIN
    EXEC sp_OAGetErrorInfo @hTCP, @src OUT, @desc OUT
    PRINT 'Error ' + CONVERT(varchar(4), @nRet)+ ': ' + @desc
    RETURN
  END
END

-- destroy TCP object
EXEC @nRet = sp_OADestroy @hTCP
IF @nRet <> 0
BEGIN
  EXEC sp_OAGetErrorInfo @hTCP, @src OUT, @desc OUT
  PRINT 'Error ' + CONVERT(varchar(4), @nRet)+ ': ' + @desc
  RETURN
END

-- return retrieved URL
SELECT @sSource

Copyright © 1996-2010 OstroSoft. All rights reserved. info@ostrosoft.com